Whats the difference between HttpClient.Timeout and using the WebRequestHandler timeout properties?

前端 未结 2 1815
渐次进展
渐次进展 2020-12-10 04:47

I can set the timeout of my HttpClient object directly with HttpClient.Timeout but I\'ve recently read about the WebRequestHandler cla

2条回答
  •  被撕碎了的回忆
    2020-12-10 05:32

    When you perform a SendAsync the HttpClient.Timeout is placed on the CancellationTokenSource. This means this timeout is for the entire async operation.

    On the other hand, WebRequestHandler.ReadWriteTimeout is copied to the HttpWebRequest where it is set on the request stream both ReadTimeout and WriteTimeout. So this is more a timeout at the stream level, which is ultimately a socket level timeout.

    If you set both, then if the operation takes more than HttpClient.Timeout in total it will timeout, and if a read or write from the stream takes longer than WebRequestHandler.ReadWriteTimeout it will also timeout. Though I am not sure if there is a difference in the timeout exceptions raised.

提交回复
热议问题