HttpWebRequest and Connections

The .NET Framework has a HttpWebRequest object in the System.Net namespace. This object allows you to talk to HTTP Servers.

Usually, people forget that the underlying connection created by the request is not freed up,unless you call Close() on the response. So, you hit the connection limit, and no more webrequests will go through. This is illustrated in the following example:

for(int i=0; i < 3; i++) {
HttpWebRequest r = WebRequest.Create(““) as HttpWebRequest;
HttpWebResponse w = r.GetResponse() as HttpWebResponse;

The above code is buggy, because the third request is going to hang in GetResponse().

If you close the response, by calling Response.Close() , then the underlying connection gets freed up, and the request will succeed.