每当我尝试运行我的网络应用时,我会不时收到此异常: 类型" System.AggregateException'的例外情况发生在WebApplication1.dll中但未在用户代码"
中处理异常由以下代码中的catch子句触发:
public static IEnumerable<Airport> GetAirports(string url)
{
IEnumerable<Airport> airports = null;
HttpResponseMessage response;
// write some code that retrieves the content from the url, and
// convert it to a list of airports.
using (var client = new HttpClient())
{
try
{
response = client.GetAsync(url).Result;
}
catch (Exception e)
{
throw e;
}
if (response.IsSuccessStatusCode)
{
// by calling .Result you are performing a synchronous call
var responseContent = response.Content;
// by calling .Result you are synchronously reading the result
string responseString = responseContent.ReadAsStringAsync().Result;
airports = JsonConvert.DeserializeObject<List<Airport>>
(responseString);
}
}
return airports;
}