HttpWebRequest timeout is always set to 20 secs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TechCrawler
    New Member
    • Jan 2011
    • 1

    HttpWebRequest timeout is always set to 20 secs

    Hi
    I am using the httpwebrequest object in C# (.NET FW 3.5SP1) to get the data from a webserver. When the webser is not alive, the httpWebResponse .GetResponse throws the time out exception at around 20 secs, even if I am setting my time out to 30 secs. Even if I don't set any time out, it returns back in 20 secs. Whats the deal with 20 secs and how can I change it? I have gone thru a lot of posts in forums, no breakthru yet. Please help.

    Here is my test code.
    Code:
    try
    {
    	WebRequest wrq = WebRequest.Create( "www.nonexistentwebsite.com" );
    	HttpWebRequest hwrq = ( HttpWebRequest ) wrq;
    	hwrq.Timeout = 30000;
    	hwrq.ReadWriteTimeout = 50000;
    	WebResponse wrs = wrq.GetResponse();
    	stream = wrs.GetResponseStream();
    
    	if( stream != null )
    	{
    		//analyze data
    		stream.Close();
    	}
    	
    }
    catch( Exception ex )
    {
    	ex.ToString();
    	//No matter what time out is set, this exception is reached in exactly 20 or 21 secs.
    	
    }
    Last edited by Curtis Rutland; Jan 7 '11, 10:31 PM. Reason: added code tags.
  • Sfreak
    New Member
    • Mar 2010
    • 64

    #2
    oh im sorry i misread the question...

    Comment

    Working...