简体   繁体   English

HttpClient超时时,在Web API控制器中请求会发生什么?

[英]What happens to request in Web API controller when HttpClient times out?

我试图理解当发送请求的HttpClient在服务实际完成处理并发回响应之前,发送请求的HttpClient实际超时时,基于Web API的服务控制器接收到的请求将发生什么情况。

What happens is that the HttpClient will close the underlying connection and throw a TaskCancelledException . 发生的情况是HttpClient将关闭基础连接并引发TaskCancelledException That exceptions StatusCode will indicate there has been a timeout. 这异常StatusCode将表明出现了超时。

On the WebAPI side, on the other hand, will notice the clients disconnection and set it's HttpResponse.ClientDisconnectedToken (which is of type CancellationToken ) to cancelled. 另一方面,在WebAPI端,将注意到客户端断开连接并将其HttpResponse.ClientDisconnectedToken (类型为CancellationToken )设置为取消。 More on that here 这里更多

增加HttpClient.Timeout属性的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM