c# - HttpClient.GetAsync(requestUri) not fetching the full content from url
问题描述
After upgrading the version of Microsoft.NETCore.UniversalWindowsPlatform
package in my UWP app from 5.0.0 to 6.2.9, HttpClient.GetAsync(requestUri)
is not downloading the entire content from url.
I am using HttpClient.GetAsync()
to get contents of the page and then extract some info from it. eg link.
With 5.0.0 it was working as expected and the entire page content was downloaded. But after upgrading to 6.2.9, looks like only the schema is getting downloaded and not the content.
One thing I noticed is that the location of System.Net.Http.dll has changed between the versions:
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
This is the code I am using:
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());
}
}
How to download the full content from url with 6.2.9 package?
This is the caller method.
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();
});
}
解决方案
推荐阅读
- typescript - 为什么 TypeScript 不能识别 Vue 插件的模块扩充?
- python - 与 Python 中的字典列表相关
- pentaho - Pentaho 8.0 版快照在哪里?
- java - python 文件是否应该始终包含一个类?
- python - 没有名为 bs4 的模块
- shopify - Shopify Slate v1 入门主题网格
- c - 在嵌入式软件中轻松更改外设定时器
- python - 分布式张量流无法共置节点 /job:master/task:0' 和 '/job:ps/task:0'
- php - laravel中的表单未提交
- php - PHP - 执行功能不适用于内爆