HttpWebRequest times out on second call
The WebResponse
obtained by request.GetReponse()
MUST be disposed properly. Try this (removing request.Abort()
and GC.Collect()
calls):
using (var wresponse = request.GetResponse())
{
using (Stream objStream = wresponse.GetResponseStream())
{
// ...
}
}
Edit: Since it still does not work, I suggest you to test this with an empty windows application. This way, you could isolate app.config problems or maximum concurrent calls per host* (are you using other webrequest object somewhere else in your application to this host; which webresponse are not disposed properly?).
Hope this solve your problem, I am out of ideas!
- See Jon Skeet's answer here.
On the heels of the previous answers, I wanted to add a couple more things. By default HttpWebRequest
allows only 2 connections to the same host (this is HTTP 1.1 "niceness"),
Yes, it can be overriden, no I won't tell you how in this question, you have to ask another one :) I think you ought to look at this post.
I think that you are still not quite disposing of all your resources connected with the HttpWebRequest, so the connection pooling comes into play and that's the problem. I wouldn't try to fight the 2 connections per server rule, unless you really have to.
As one of the posters above noted, Fiddler is doing you a bit of a disservice in this case.
I'd add a nice finally {}
clause after your catch and make sure that as the above post notes, all streams are flushed, closed and references to the request object are set to null.
Please let us know if this helps.