HttpWebRequest timeout

my code is:

System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://192.168.2.2/web/movielist");
req.Timeout = 2000;
System.Net.WebResponse res = req.GetResponse();
System.IO.Stream responseStream = res.GetResponseStream();

The requested document (movielist) is a very large document, and it takes more than 10 seconds to complete.

I want to set only a timeout to establish the connection itself. As far as I can see, req.Timeout is a timeout for the whole request, which not only establishes a connection. There must not be a timeout to receive the document.

+5
source share
1 answer

This timeout is in milliseconds - so 2000ms = only 2 seconds. You cannot specify a connection timeout - timeout for the entire request. Try changing 2000 to 20,000 (20 seconds) or higher to avoid timeouts.

+1
source

All Articles