imlokesh
imlokesh

Reputation: 2739

How do I specify a global HttpWebRequest timeout?

I'm using a twitter library that uses HttpWebRequest internally to make requests to the twitter API. For some odd reason, the requests sometimes take a lot of time to complete (~10 minutes).

The HttpWebRequest object is not exposed by the library.

Is there any way to specify a global timeout and readwritetimeout for the requests, perhaps via app.config?

Upvotes: 7

Views: 4140

Answers (2)

Iain
Iain

Reputation: 10779

Unfortunately not currently possible. The constructor of HttpWebRequest has this value hardcoded - reference source.

Upvotes: 3

Krushnakant Ladani
Krushnakant Ladani

Reputation: 673

That timeout is in milliseconds - so 2000ms = only 2 seconds.

System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("URL");
req.Timeout = Convert.ToInt32(ConfigurationManager.AppSettings["timeOut"]);
Req.ReadWriteTimeout = Convert.ToInt32(ConfigurationManager.AppSettings["readWriteTimeout "]);

App.config

<appSettings>
<add key="timeOut" value="200" />
<add key="readWriteTimeout " value="10000" />
</appSettings>

Timeout = time spent trying to establish a connection (not including lookup time)

ReadWriteTimeout = time spent trying to read or write data after connection established

Upvotes: -1

Related Questions