在我的UWP应用中将Microsoft.NETCore.UniversalWindowsPlatform
软件包的版本从5.0.0升级到6.2.9之后,HttpClient.GetAsync(requestUri)
并没有从url下载全部内容。
我正在使用HttpClient.GetAsync()
获取页面内容,然后从页面中提取一些信息。 eg link。
使用5.0.0时,它可以按预期工作,并且下载了整个page content。但是升级到6.2.9后,看起来只有架构在downloaded and not the content中。
我注意到的一件事是System.Net.Http.dll的位置在两个版本之间已更改:
5.0.0:C:\ Users \ xx.nuget \ packages \ system.net.http \ 4.0.0 \ ref \ netcore50 \ System.Net.Http.dll
6.2.9:C:\ Program Files(x86)\ Microsoft SDKs \ UWPNuGetPackages \ system.net.http \ 4.1.0 \ ref \ netcore50 \ System.Net.Http.dll
< / li>这是我正在使用的代码:
public static async void GetDataAsync(string url, Action<string> OnSuccess, Action<string> OnFailure)
{
HttpClient _floatHttpClient = new HttpClient();
string responseText = null;
try
{
HttpResponseMessage response = await _floatHttpClient.GetAsync(url);
response.EnsureSuccessStatusCode();
responseText = await response.Content.ReadAsStringAsync();
OnSuccess(responseText);
}
catch (Exception ex)
{
OnFailure(ex.ToString());
}
}
如何使用6.2.9软件包从url下载全部内容?
这是调用方方法。
private void def_click(object sender, RoutedEventArgs e)
{
DictDialog dictDialog = new DictDialog(Contentgrid.ActualWidth, Contentgrid.ActualHeight);
dictDialog.ShowAsync();
string url = "https://www.bing.com/search?q=+definition:" + dictWord + "&setmkt=en-us&setlang=en-us";
WebRequest.GetDataAsync(url, (string html) =>
{
if (html != null)
{
bool defFound = false;
string def = readerVM.GetDefinitionBing(html, out defFound);
if (defFound == true)
{
dictDialog.LoadHtml(def);
}
else
{
dictDialog.ShowNoDefMsg();
}
}
else
{
dictDialog.LoadFailed();
}
},
(string error) =>
{
dictDialog.LoadFailed();
});
}