我无法接收来自http网络服务的json数据,因为数据大小 - 我猜 - 这是7 MB,我首先尝试了这个:
private async Task<string> GetResponse(string url)
{
HttpResponseMessage response = null;
HttpClient client = new HttpClient();
try
{
response = await client.GetAsync(url);
}
catch (Exception )
{
throw;
}
return await response.Content.ReadAsStringAsync();
}
但它给了我“任务取消异常”,经过一些搜索,我发现它可能是请求超时限制问题,所以我通过将超时限制设置为两分钟来实现第二个解决方案:
HttpClient client = new HttpClient();
client.Timeout = new TimeSpan(0, 2, 0);
执行时,没有结果,没有异常,并且方法
处的应用程序阻塞client.GetAsync(url);