Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpWebRequest Timeout

my Code:

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 big document and it requires more than 10 seconds to retrieve it complete.

I want to only set a timeout for establishing the connection itself. As far as i can see req.Timeout is a timeout for the whole request not only establishing the connection. There should be no timeout for retrieving the document.

like image 716
Hans99 Avatar asked Nov 15 '22 08:11

Hans99


1 Answers

That timeout is in milliseconds - so 2000ms = only 2 seconds. You can't specify a connection establish timeout - the timeout is for the whole request. Try changing 2000 to 20000 (20 seconds) or higher to avoid timeouts.

like image 67
Matt Chepeleff Avatar answered Dec 06 '22 06:12

Matt Chepeleff