In my tests, I don't see the HttpClient raising the TimeOut exception.
It will tell you that Task is Cancelled through IsCancelled.
rossco
When calling GetAsync and using the ContinueWith callback, checking the Task response Exception property, it is always null.
You need to check the StatusCode(500 for server error)
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
First Try to catch WebException to determine the timeout and then catch HttpRequestException for other errors
"HttpClient.Timeout
The default value is 100,000 milliseconds (100 seconds).
A Domain Name System (DNS) query may take up to 15 seconds to return or time out. If your request contains a host name that requires resolution and you set
Timeout to a value less than 15 seconds, it may take 15 seconds or more before a
WebException is thrown to indicate a timeout on your request."
rossco
Member
26 Points
12 Posts
HttpClient and Timeouts
Jun 13, 2012 03:04 PM|LINK
Hi,
How can you tell the difference if a HttpClient request timed out or was cancelled?
From a Task<HttpResponseMessage> object the only flag set in both cases appears to be the IsCanceled property.
If a task times out, I'd like to throw an exception and if it's cancelled via a CancellationToken then ignore it.
Thanks,
Ross
Mudasir.Khan
All-Star
15346 Points
3142 Posts
Re: HttpClient and Timeouts
Jun 13, 2012 03:26 PM|LINK
server wont throw TimeOut Exception exception.
client waits for configured amount of time then by itself TimeOut Exception is raised
rossco
Member
26 Points
12 Posts
Re: HttpClient and Timeouts
Jun 13, 2012 03:39 PM|LINK
It's on the client side.
In my tests, I don't see the HttpClient raising the TimeOut exception.
When calling GetAsync and using the ContinueWith callback, checking the Task response Exception property, it is always null.
How did you get the HttpClient object to raise the Timeout Exception?
Thanks,
Ross
imran_ku07
All-Star
45864 Points
7713 Posts
MVP
Re: HttpClient and Timeouts
Jun 17, 2012 10:25 AM|LINK
It will tell you that Task is Cancelled through IsCancelled.
You need to check the StatusCode(500 for server error)
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
rossco
Member
26 Points
12 Posts
Re: HttpClient and Timeouts
Jun 19, 2012 04:43 PM|LINK
When I get a timeout, the result object is null, so I cannot get to the StatusCode on the HttpResponseMessage message to check.
Is the only place to get to the StatusCode from the HttpResponseMessage object or is there another place I'm not aware of.
Thanks,
Ross
imran_ku07
All-Star
45864 Points
7713 Posts
MVP
Re: HttpClient and Timeouts
Jun 23, 2012 10:04 AM|LINK
Which Timeout areyou refferring. I am talking about HttpCliet.Timeout.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
alvingeorge
Participant
925 Points
203 Posts
Re: HttpClient and Timeouts
Jun 24, 2012 03:19 PM|LINK
Hi Ross,
First Try to catch WebException to determine the timeout and then catch HttpRequestException for other errors
"HttpClient.Timeout
The default value is 100,000 milliseconds (100 seconds).
A Domain Name System (DNS) query may take up to 15 seconds to return or time out. If your request contains a host name that requires resolution and you set Timeout to a value less than 15 seconds, it may take 15 seconds or more before a WebException is thrown to indicate a timeout on your request."
msdn.microsoft.com/en-us/library/system.net.http.httpclient.timeout(v=vs.110).aspx