当前位置: 首页>>代码示例>>C#>>正文


C# HttpClient.GetBufferAsync方法代码示例

本文整理汇总了C#中HttpClient.GetBufferAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.GetBufferAsync方法的具体用法?C# HttpClient.GetBufferAsync怎么用?C# HttpClient.GetBufferAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpClient的用法示例。


在下文中一共展示了HttpClient.GetBufferAsync方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Button_Click

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            //this.txt.Text = DateTime.Now.ToString();
            //string x = "";
            //HttpClient h = new HttpClient();
            //try
            //{
            //    var response = h.GetBufferAsync(new Uri("http://202.202.43.125/"));

            //    x = await h.GetStringAsync(new Uri("http://202.202.43.125/"));
            //}
            //catch (Exception xx)
            //{
            //    Debug.WriteLine(xx.Message);
            //}
            //Debug.WriteLine(x);
            //Debug.WriteLine("-=--------------------------------------------------------");
            ////异步执行并得到结果
            //x = await getstring(new Uri("http://202.202.43.125/"));
            ////异步赋值在执行
            //Task<string> rrrrr = getstring(new Uri("http://202.202.43.125/"));
            //var c = await rrrrr;
            //Debug.WriteLine(x);
            HttpClient httpclient = new HttpClient();
            var uri = new Uri("http://apis.baidu.com/songshuxiansheng/real_time/search_news?keyword=明星");
            httpclient.DefaultRequestHeaders.Add("apikey", "9a84555d8b243d4afa83cac9855b60e7");
            var response = await httpclient.GetAsync(uri);
            var r2 = await httpclient.GetStringAsync(uri);
            var r3 = await httpclient.GetBufferAsync(uri);
            var r33 = r3.ToArray();
            string result = Encoding.UTF8.GetString(r33);
            string humanlike = Decode(result);
            string text = "Aa0严";
            var cccccccc = Encoding.Unicode.GetBytes(text);
            Debug.Write(humanlike);
            //char[] aaaa =
            //{
            //   (Char)0x4ed6,(Char)0x662f,(Char)0x5a31,(Char)0x4e50,(Char)0x5708,(Char)0x91cc,(Char)0x6700,(Char)0x5bd2,(Char)0x9178,(Char)0x7684,(Char)0x660e,(Char)0x661f,(Char)0xff0c,(Char)0x5374,(Char)0x503c,(Char)0x5f97,(Char)0x6bcf,(Char)0x4e00,(Char)0x4e2a,(Char)0x4eba,(Char)0x5c0a,(Char)0x91cd,(Char)0xff01
            //};
            //foreach (var VARIABLE in aaaa)
            //{
            //    Debug.Write(VARIABLE);
            //}
        }
开发者ID:Iamnvincible,项目名称:csharppractice,代码行数:44,代码来源:MainPage.xaml.cs

示例2: DownloadBufferAsync

        public async static System.Threading.Tasks.Task<IBuffer> DownloadBufferAsync(Uri url)
        {
            //Turn off cache for live playback
            var filter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
            filter.CacheControl.WriteBehavior = Windows.Web.Http.Filters.HttpCacheWriteBehavior.NoCache;
            using (var httpClient = new HttpClient(filter))
            {
                try
                {
                    var buffer = await httpClient.GetBufferAsync(url);
#if DEBUG
                    Logger.Log("GetBufferAsync suceeded for url: " + url);
#endif
                    return buffer;
                }
                catch (Exception e)
                {
#if DEBUG
                    Logger.Log("GetBufferAsync exception for url: " + url + " HRESULT 0x" + e.HResult.ToString("x"));
#endif
                    return null;
                }
            }
        }
开发者ID:chgeuer,项目名称:playready_livedash_UWP,代码行数:24,代码来源:utils.cs

示例3: SaveFile

 private async Task SaveFile(StorageFile file)
 {
     string url = ViewModel.Wallpaper.GetCacheUrl(AppSetting.WallpaperSize);
     using (HttpClient client = new HttpClient())
     {
         await FileIO.WriteBufferAsync(file, await client.GetBufferAsync(new Uri(url)));
     }
 }
开发者ID:h82258652,项目名称:MSDevUnion.BingWallpaper,代码行数:8,代码来源:DetailView.xaml.cs

示例4: GetWallpaperFile

 /// <summary>
 /// 获取当前壁纸文件。该方法用于壁纸设置和锁屏。
 /// </summary>
 /// <returns></returns>
 private async Task<StorageFile> GetWallpaperFile()
 {
     var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(Guid.NewGuid().ToString());
     using (HttpClient client = new HttpClient())
     {
         string url = ViewModel.Wallpaper.GetCacheUrl(AppSetting.WallpaperSize);
         await FileIO.WriteBufferAsync(file, await client.GetBufferAsync(new Uri(url)));
     }
     return file;
 }
开发者ID:h82258652,项目名称:MSDevUnion.BingWallpaper,代码行数:14,代码来源:DetailView.xaml.cs

示例5: GetImageData

 private async Task<byte[]> GetImageData()
 {
     using (HttpClient client = new HttpClient())
     {
         return (await client.GetBufferAsync(new Uri(ViewModel.Wallpaper.GetCacheUrl(AppSetting.WallpaperSize)))).ToArray();
     }
 }
开发者ID:h82258652,项目名称:MSDevUnion.BingWallpaper,代码行数:7,代码来源:DetailView.xaml.cs

示例6: GetThumbnailDataAsync

 private async Task<byte[]> GetThumbnailDataAsync()
 {
     using (HttpClient client = new HttpClient())
     {
         return (await client.GetBufferAsync(new Uri(_feed.PicMid))).ToArray();
     }
 }
开发者ID:h82258652,项目名称:SoftwareKobo.U148For10,代码行数:7,代码来源:DetailView.xaml.cs

示例7: UriSourceChanged

        private async void UriSourceChanged()
        {
            IsLoading = true;

            #region 清空之前的图像

            using (var emptyStream = new InMemoryRandomAccessStream())
            {
                SetSource(emptyStream);
            }

            #endregion 清空之前的图像

            // 清空图像。
            if (UriSource == null)
            {
                IsLoading = false;
                return;
            }

            var bitmapImage = UriSource as BitmapImage;
            var uri = bitmapImage != null ? bitmapImage.UriSource : null;
            if (uri == null)
            {
                IsLoading = false;
                throw new InvalidOperationException("not support image source");
            }

            var requestTime = DateTime.Now;
            _lastRequestTime = requestTime;

            var scheme = uri.Scheme;
            if (scheme == "http" || scheme == "https")
            {
                // 网络图像。
                byte[] networkImageDatas;

                // 获取本地对应的缓存路径。
                var cachePath = GetCachePath(uri);

                // 本地图片缓存文件是否存在。
                var isCacheExist = IsCacheExist(cachePath);

                if (isCacheExist == false)
                {
                    // 缓存不存在,下载图像。
                    using (var client = new HttpClient())
                    {
                        try
                        {
                            networkImageDatas = (await client.GetBufferAsync(uri)).ToArray();
                        }
                        catch (Exception ex)
                        {
                            // 下载失败。
                            if (ImageFailed != null)
                            {
                                ImageFailed(this, new ImageFailedEventArgs(ex));
                            }
                            IsLoading = false;
                            return;
                        }
                    }

                    // 下载成功,保存到独立存储。
                    await SaveImageAsync(cachePath, networkImageDatas);
                }
                else
                {
                    // 缓存存在,加载独立存储中的缓存图像。
                    networkImageDatas = await LoadCachedImageAsync(cachePath);
                }

                // 加载图像。
                using (var stream = new MemoryStream(networkImageDatas))
                {
                    try
                    {
                        await SetStreamAsync(stream.AsRandomAccessStream(), requestTime);
                    }
                    catch (Exception ex)
                    {
                        if (ImageFailed != null)
                        {
                            ImageFailed(this, new ImageFailedEventArgs(ex));
                        }

                        // 丢弃缓存。
                        RemoveCachedImage(uri);

                        IsLoading = false;
                        return;
                    }
                }
            }
            else
            {
                // 本地图像。
                if (DesignMode.DesignModeEnabled == false)
                {
//.........这里部分代码省略.........
开发者ID:h82258652,项目名称:SoftwareKobo.UniversalToolkit,代码行数:101,代码来源:StorageCachedImage.cs

示例8: SaveFile

 private async Task SaveFile(StorageFile file)
 {
     string url = ViewModel.Wallpaper.GetCacheUrl(AppSetting.WallpaperSize);
     try
     {
         using (HttpClient client = new HttpClient())
         {
             await FileIO.WriteBufferAsync(file, await client.GetBufferAsync(new Uri(url)));
         }
         await new MessageDialog("保存成功").ShowAsync();
     }
     catch
     {
         await new MessageDialog("保存失败").ShowAsync();
     }
 }
开发者ID:higankanshi,项目名称:MSDevUnion.BingWallpaper,代码行数:16,代码来源:DetailView.xaml.cs


注:本文中的HttpClient.GetBufferAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。