【发布时间】:2018-08-21 14:11:36
【问题描述】:
我有一个程序,我想在其中从 Internet 下载图像。我遵循了本教程:How to download and store an image using Windows.Web.Http?。
这是我的源代码:
Uri uri = new Uri(CoverImage);
string filename = BookNameTextBox.Text + ".jpg";
StorageFile destinationFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(filename);
HttpClient client = new HttpClient();
var buffer = await client.GetBufferAsync(uri);
StorageFile photo = await ApplicationData.Current.LocalFolder.GetFileAsync(CoverImage);
程序无法编译。它说,“HttpClient 不包含 'GetBufferAsync' 的定义”。在谷歌搜索时,我发现这篇文章https://docs.microsoft.com/en-us/uwp/api/windows.web.http.httpclient.getbufferasync 根据该方法存在。我不知道该怎么办。
具有讽刺意味的是,我实际上在另一个文件中使用了 HttpClient,它工作正常。这是那部分:
var http = new HttpClient();
string url = "https://www.googleapis.com/books/v1/volumes?q=" + title.Replace(' ', '+') + "&fields = items(volumeInfo(title, authors, publisher)), items/";
var response = await http.GetAsync(url);
var result = await response.Content.ReadAsStringAsync();
【问题讨论】:
-
听起来您缺少参考。你能检查一下你的项目是否引用了所需的程序集吗?
-
您的应用程序实际上是 UWP 应用程序和
HttpClient那个类 而不是this one? -
这是一个 uwp 应用程序@Damien_The_Unbeliever
-
我在另一个工作正常的文件中使用 HttpClient。但我没有使用 GetBufferAsync() @Dimitar