Ehsan
Ehsan

Reputation: 1682

browser succeed but HttpWebRequest fails (timeout)

I'm used to visit a web site (news website) frequently. after two years of successful operation the HttpWebRequest is fail with timeout operation. first i suspect that destination web site is block my ip but I can see the web site with the browser on that machine, and when I trace the request with Fiddler it shows that it can download the page in 143 ms. so there is no problem with the destination. then i tried to set all request header that browser sent to web server but it still has problem and timeout. (browser shows that response is fast enough (143ms) and there is no reason for timeout error.

NOTE: the application is running perfectly on other machine with different ip address

Can someone show me the trick ?

Upvotes: 2

Views: 3140

Answers (1)

Ehsan
Ehsan

Reputation: 1682

After searching for a while and playing with Fiddler I found out that I should send the request with Keep-Alive, in Http 1.1 the first request is enable with Keep-Alive header but the consequent requests remove this header as it use the same connection for other request. so in my case the target website needs to have Keep-Alive header with all requests otherwise it gets timeout I solve this problem with the following question

C# - Connection: keep-alive Header is Not Being Sent During HttpWebRequest

Upvotes: 2

Related Questions