public static async Task<string> HttpGets(string uri) { if (Config.IsNetWork) { NotifyControl notify = new NotifyControl(); notify.Text = "亲,努力加载中..."; notify.Show(); using (HttpClient httpClient = new HttpClient()) { try { HttpResponseMessage response = new HttpResponseMessage(); response = await httpClient.GetAsync(new Uri(uri, UriKind.Absolute)); responseString = await response.Content.ReadAsStringAsync(); notify.Hide(); } catch (Exception ex) { Debug.WriteLine(ex.Message.ToString()); } } } return responseString; }
public static async Task<string> HttpGet(string uri) { if (Config.IsNetWork) { NotifyControl notify = new NotifyControl(); notify.Text = "亲,努力加载中..."; notify.Show(); var _filter = new HttpBaseProtocolFilter(); using (HttpClient httpClient = new HttpClient(_filter)) { _filter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.NoCache; HttpResponseMessage response = new HttpResponseMessage(); response = await httpClient.GetAsync(new Uri(uri, UriKind.Absolute)); responseString = await response.Content.ReadAsStringAsync(); notify.Hide(); } } return responseString; }
public async void HttpPost(string uid, string uimage, string name, string content, List<string> imagePsthList, string songPath,string date,int type) { NotifyControl notify = new NotifyControl(); notify.Text = "亲,努力发送中..."; notify.Show(); HttpClient httpClient = new HttpClient(); uint MaxImageWidth = 480; uint MaxImageHeight = 800; uint width; uint height; try { string posturi = Config.apiDreamingPublish; HttpMultipartFormDataContent fileContent = new HttpMultipartFormDataContent(); if (imagePsthList.Count > 0) { for (int i = 0; i < imagePsthList.Count; i++) { StorageFile inFile = await StorageFile.GetFileFromPathAsync(imagePsthList[i]); var inStream = await inFile.OpenReadAsync(); InMemoryRandomAccessStream outStream = new InMemoryRandomAccessStream(); BitmapDecoder decoder = await ImageHelp.GetProperDecoder(inStream,inFile); if (decoder == null) return; if (decoder.OrientedPixelWidth > MaxImageWidth && decoder.OrientedPixelHeight > MaxImageHeight) { width = MaxImageWidth; height = MaxImageHeight; } else { width = decoder.OrientedPixelWidth; height = decoder.OrientedPixelHeight; } PixelDataProvider provider = await decoder.GetPixelDataAsync(); byte[] data = provider.DetachPixelData(); //获取像素数据的字节数组 BitmapPropertySet propertySet = new BitmapPropertySet(); BitmapTypedValue qualityValue = new BitmapTypedValue(0.5, PropertyType.Single); propertySet.Add("ImageQuality", qualityValue); var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, outStream, propertySet);//建立编码器 encoder.SetPixelData(decoder.BitmapPixelFormat, decoder.BitmapAlphaMode, decoder.OrientedPixelWidth, decoder.OrientedPixelHeight, decoder.DpiX, decoder.DpiY, data ); encoder.BitmapTransform.ScaledWidth = width; encoder.BitmapTransform.ScaledHeight = height; await encoder.FlushAsync(); HttpStreamContent streamContent1 = new HttpStreamContent(outStream); fileContent.Add(streamContent1, "pic", inFile.Name); } } if (songPath != null) { StorageFile file1 = await StorageFile.GetFileFromPathAsync(songPath); IRandomAccessStreamWithContentType stream1 = await file1.OpenReadAsync(); HttpStreamContent streamContent1 = new HttpStreamContent(stream1); fileContent.Add(streamContent1, "song", file1.Name); } HttpStringContent stringContent = new HttpStringContent(content); HttpStringContent stringName = new HttpStringContent(name); HttpStringContent stringUid = new HttpStringContent(uid); HttpStringContent stringUimage = new HttpStringContent(uimage); HttpStringContent stringTime = new HttpStringContent(date); HttpStringContent stringType = new HttpStringContent(type.ToString()); fileContent.Add(stringContent, "content"); fileContent.Add(stringUid, "phone"); fileContent.Add(stringUimage, "uimage"); fileContent.Add(stringName, "name"); fileContent.Add(stringTime, "time"); fileContent.Add(stringType, "type"); HttpResponseMessage response = await httpClient.PostAsync(new Uri(posturi), fileContent); Init(); notify.Hide(); PostCommand.CanExecutes = true; NavigationHelp.NavigateTo(typeof(AllDreaming)); } catch (Exception ex) { HelpMethods.Msg(ex.Message.ToString()); } }