首页 > 解决方案 > 如何解决.net5.0中的超时异常“System.Net.WebException:操作已超时”

问题描述

我是 ASP.net 5.0 的新手。我正在尝试从此 API https://dev.timeanddate.com/docs/holidays/获取结果

我尝试使用以下代码作为文档,

 public async Task<IActionResult> Get([FromQuery] string countryCode, int year)
        {
            var service = new HolidaysService("key", "pass");
            service.Types = HolidayType.Federal | HolidayType.Weekdays;
            var result = await service.HolidaysForCountryAsync(countryCode, year);
            return Ok(result);
        }

API 在浏览器中运行良好,无需花费太多时间。https://api.xmltime.com/holidays?accesskey=dYjG8ztthf&secretkey=veUV06dNmrnp7bbaYq0u&version=3&country=ro&year=2021&lang=en

但对我来说,我得到了这个例外,

   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
   at System.Net.WebClient.GetWebResponseTaskAsync(WebRequest request)
   at System.Net.WebClient.DownloadBitsAsync(WebRequest request, Stream writeStream, AsyncOperation asyncOp, Action`3 completionDelegate)
   at TimeAndDate.Services.BaseService.SendRequestAsync(NameValueCollection args)
   at TimeAndDate.Services.BaseService.CallServiceAsync[T](NameValueCollection args, Func`2 parser)
   at TimeAndDate.Services.HolidaysService.HolidaysForCountryAsync(String countryCode, Int32 year)```

How can I get Result postman without timeout Exception ?

标签: c#timeoutexceptionasp.net5

解决方案


推荐阅读