I can set the timeout of my HttpClient
object directly with HttpClient.Timeout
but I've recently read about the WebRequestHandler
class which is a derivative of HttpClientHandler
.
WebRequestHandler
has a ReadWriteTimeout
property. How will this affect the operation of the request when used alongside HttpClient.Timeout
?
WebRequestHandler.ReadWriteTimeout
- Gets or sets a time-out in milliseconds when writing a request to or reading a response from a server.HttpClient.Timeout
- Gets or sets theTimeSpan
to wait before the request times out.Here,
WebRequestHandler
is a wrapper overHTTPClient
WebRequestHandler
derives fromHttpClientHandler
but adds properties that generally only are available on full .NET. To conclude, it is more on less same thing.For more info refer this link - http://blogs.msdn.com/b/henrikn/archive/2012/08/07/httpclient-httpclienthandler-and-httpwebrequesthandler.aspx
When you perform a
SendAsync
theHttpClient.Timeout
is placed on theCancellationTokenSource
. This means this timeout is for the entire async operation.On the other hand,
WebRequestHandler.ReadWriteTimeout
is copied to theHttpWebRequest
where it is set on the request stream bothReadTimeout
andWriteTimeout
. 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 thanWebRequestHandler.ReadWriteTimeout
it will also timeout. Though I am not sure if there is a difference in the timeout exceptions raised.