Active Directory Products
Calls To Calendar
SMS To CSV
SMS To Gmail
Voicemail To Gmail
How Long For Me
<< Back To All Blogs
Resolving Odd 5 Minute Timeout in HttpWebRequest.
Monday, December 7th, 2009
Recently I have been using the HttpWebRequest class a large amount, and we came across a scenario in which I was continually getting a timeout, but I had been setting the Timeout property of the HttpWebRequest to much larger than 5 minutes, but was still receiving the timeout.
In this case we were using an synchronous call through a StreamReader to get back all of the data as simple text:
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = reader.ReadToEnd();
It was timing out on reader.ReadToEnd() which made me suspicious of a possible stream timeout, and after some digging that was indeed the case.
The stream reading abilities of HttpWebRequest will by default timeout at 5 minutes (300 seconds), and in order to get around this issue you need to set the ReadWriteTimeout property, such as follows:
request.ReadWriteTimeout = 600; // In seconds, so this would be 10 minutes
This will not apply to asynchronous requests, just as a note of interest.
A rather simple issue, but was very frustrating at first as we were trying to simply increase the Timeout property.
Timeoutin' Tom Out.
Resolving ASP.NET Web.Config Inheritance
Validate a Windows Username and Password against Active Directory
Impersonating a user in ASP.NET
Configuring ASP.NET (And SharePoint) to use SQL-based Sessions
Writing console output from a Windows form in C#
Mike said on Tuesday, February 28th, 2012 @ 11:39 AM
ReadWriteTimeout should be set in milliseconds, not seconds. 600 = 6/10 of a second
Add A Comment
Email Address: (not public, used to send notifications on further comments)
Enter the text above, except for the 1st and last character: