How to specify global timeout HttpWebRequest?

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

The HttpWebRequest object HttpWebRequest not displayed by the library.

Is it possible to specify a global timeout and readwritetimeout for requests, perhaps through app.config?

+5
source share
2 answers

Unfortunately, it is currently impossible. The HttpWebRequest constructor has this hardcoded value - a reference source .

+2
source

This 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> 

Latency = time taken to establish a connection (not including search time)

ReadWriteTimeout = time spent reading or writing data after establishing a connection

-2
source

Source: https://habr.com/ru/post/1202011/


All Articles