public static async void HttpPost(string id, string phone, string image, string name, string content, string time, string atName, string atPhone, string atImage) { try { HttpClient httpClient = new HttpClient(); string posturi = Config.apiCommentPublish; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri(posturi)); HttpFormUrlEncodedContent postData = new HttpFormUrlEncodedContent( new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("id", id), new KeyValuePair <string, string>("phone", phone), new KeyValuePair <string, string>("image", image), new KeyValuePair <string, string>("name", name), new KeyValuePair <string, string>("content", content), new KeyValuePair <string, string>("time", time), new KeyValuePair <string, string>("atName", atName), new KeyValuePair <string, string>("atPhone", atPhone), new KeyValuePair <string, string>("atImage", atImage), } ); request.Content = postData; HttpResponseMessage response = await httpClient.SendRequestAsync(request); } catch (Exception ex) { HelpMethods.Msg(ex.Message.ToString()); } }
public static async void HttpPost(string phone, string password) { try { HttpClient httpClient = new HttpClient(); string posturi = Config.apiUserRegister; string date = DateTime.Now.Date.Year.ToString() + "-" + DateTime.Now.Date.Month.ToString() + "-" + DateTime.Now.Date.Day.ToString(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri(posturi)); HttpFormUrlEncodedContent postData = new HttpFormUrlEncodedContent( new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("phone", phone), //手机号 new KeyValuePair <string, string>("password", password), //密码 new KeyValuePair <string, string>("date", date), //注册日期 } ); request.Content = postData; HttpResponseMessage response = await httpClient.SendRequestAsync(request); string responseString = await response.Content.ReadAsStringAsync(); JsonObject register = JsonObject.Parse(responseString); try { int code = (int)register.GetNamedNumber("code"); switch (code) { case 0: { JsonObject user = register.GetNamedObject("user"); Config.UserPhone = user.GetNamedString("phone"); NavigationHelp.NavigateTo(typeof(UserData)); break; } case 1: HelpMethods.Msg("手机号已注册!"); break; case 2: HelpMethods.Msg("未知错误!"); break; default: break; } } catch (Exception ex) { HelpMethods.Msg(ex.Message.ToString()); } } catch (Exception ex) { HelpMethods.Msg(ex.Message.ToString()); } }
public static async void HttpPost(string cid, string cname, string cimage, string cdream, string fid, string fname, string fimage, string fdream) { try { HttpClient httpClient = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri(Config.apiUserFollow)); HttpFormUrlEncodedContent postData = new HttpFormUrlEncodedContent( new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("cphone", cid), new KeyValuePair <string, string>("cname", cname), new KeyValuePair <string, string>("cimage", cimage), new KeyValuePair <string, string>("cdream", cdream), new KeyValuePair <string, string>("fphone", fid), new KeyValuePair <string, string>("fname", fname), new KeyValuePair <string, string>("fimage", fimage), new KeyValuePair <string, string>("fdream", fdream), } ); request.Content = postData; HttpResponseMessage response = await httpClient.SendRequestAsync(request); string responseString = await response.Content.ReadAsStringAsync(); } catch (Exception ex) { HelpMethods.Msg(ex.Message.ToString()); } }
public static async void HttpUserPost(string phone, string name, string content, string picPath, string tag) { HttpClient httpClient = new HttpClient(); try { string posturi = Config.apiUserUpdate; StorageFile file1 = await StorageFile.GetFileFromPathAsync(picPath); IRandomAccessStreamWithContentType stream1 = await file1.OpenReadAsync(); HttpStreamContent streamContent1 = new HttpStreamContent(stream1); HttpStringContent stringContent = new HttpStringContent(content); HttpStringContent stringTitle = new HttpStringContent(phone); HttpStringContent stringName = new HttpStringContent(name); HttpStringContent stringTag = new HttpStringContent(tag); HttpMultipartFormDataContent fileContent = new HttpMultipartFormDataContent(); fileContent.Add(stringContent, "dream"); fileContent.Add(stringTitle, "phone"); fileContent.Add(stringTag, "tag"); fileContent.Add(stringName, "name"); fileContent.Add(streamContent1, "picture", "pic.jpg"); HttpResponseMessage response = await httpClient.PostAsync(new Uri(posturi), fileContent); string responString = await response.Content.ReadAsStringAsync(); if ((int)response.StatusCode == 200) { JsonObject user = JsonObject.Parse(responString); Config.UserName = user.GetNamedString("name"); Config.UserImage = Config.apiFile + user.GetNamedString("image"); Config.UserPhone = user.GetNamedString("phone"); Config.UserDream = user.GetNamedString("dream"); Config.UserTag = user.GetNamedString("tag"); NavigationHelp.NavigateTo(typeof(Main)); } } catch (Exception ex) { HelpMethods.Msg(ex.Message.ToString()); } }
public static async Task <string> GetImagePath(StorageFile file) { string ImagePath = null; StorageFile imageFile = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(file.Name, CreationCollisionOption.ReplaceExisting); var inStream = await file.OpenAsync(FileAccessMode.Read); var outStream = await imageFile.OpenAsync(FileAccessMode.ReadWrite); outStream.Size = 0; BitmapDecoder decoder = await BitmapDecoder.CreateAsync(inStream); PixelDataProvider provider = await decoder.GetPixelDataAsync(); byte[] data = provider.DetachPixelData(); var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, outStream); encoder.SetPixelData(decoder.BitmapPixelFormat, decoder.BitmapAlphaMode, decoder.PixelWidth, decoder.PixelHeight, decoder.DpiX, decoder.DpiY, data ); try { await encoder.FlushAsync(); ImagePath = imageFile.Path; } catch (Exception err) { HelpMethods.Msg(err.Message.ToString()); } finally { inStream.Dispose(); outStream.Dispose(); } return(ImagePath); }
public static async void HttpPost(string phone, string password) { try { HttpClient httpClient = new HttpClient(); string posturi = Config.apiUserLogin; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri(posturi)); HttpFormUrlEncodedContent postData = new HttpFormUrlEncodedContent( new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("phone", phone), //手机 new KeyValuePair <string, string>("password", password), //密码 } ); request.Content = postData; HttpResponseMessage response = await httpClient.SendRequestAsync(request); string responseString = await response.Content.ReadAsStringAsync(); Debug.WriteLine(responseString); JsonObject login = JsonObject.Parse(responseString); try { int code = (int)login.GetNamedNumber("code"); switch (code) { case 0: { JsonObject user = login.GetNamedObject("user"); Config.UserName = user.GetNamedString("name"); Config.UserImage = Config.apiFile + user.GetNamedString("image"); Config.UserPhone = user.GetNamedString("phone"); Config.UserDream = user.GetNamedString("dream"); Config.UserTag = user.GetNamedString("tag"); NavigationHelp.NavigateTo(typeof(Main)); break; } case 1: HelpMethods.Msg("手机号未注册!"); break; case 2: HelpMethods.Msg("密码错误!"); break; default: break; } } catch (Exception ex) { HelpMethods.Msg("服务器出错!"); Debug.WriteLine(ex.Message.ToString()); } } catch (Exception ex) { HelpMethods.Msg(ex.Message.ToString()); } }