c# - 如何解决.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 ?
解决方案
推荐阅读
- css - 使用 javascript 文字时未应用 Angular 类
- javascript - Javascript下载文件并回读修改
- reactjs - 您如何通过将令牌存储在本地存储中来保持用户登录使用?
- css - 如何将动态 url 链接传递到 Angular 中的内联 css?
- javascript - 如何使用 JavaScript 在范围滑块间隔上添加 CSS 类?
- javascript - clientX 和 clientY 从真实坐标偏移
- typescript - 如何获取 News API 并在 Vuetify.js 卡片组件中显示数据?
- javascript - 获取 ERC20 的所有权数组
- extract - Excel公式提取第二个斜杠之前的字符串部分,其中之间的文本可能是不同的长度
- java - 我正在尝试打印未对齐的金字塔