public void Test()
{
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)
request.GetResponse() ;
Console.WriteLine("Trying to close stream");
response.Close();
Console.WriteLine("Stream Closed");
if you comment out the Close(); you can get up to two connections.
Anyone seen a workaround for this
Thanks

HttpWebResponse close() hangs
Adriaan W
I'm assuming you've probably already come across this
http://blogs.msdn.com/feroze_daud/archive/2004/01/21/61400.aspx
Hi!
There are many reasons why GetResponse() might hang. Some are:
1) You have reached the connection limit on the client ( 2 conns per http/1.1 server, 4 connections per http/1.0 server, or custom limit set on the ServicePoint), and no connection is free to send a request to the server. In other words, you might have 2 requests outstanding (eg: to a 1.1 server) which are taking more than 2 minutes to complete, and then issue another GetResponse() to the same server. The last getresponse() might time out.
2) You have not closed the response stream of an earlier httpwebresponse. So, even if a connection is free, the request wont be sent.
3) The server is taking too long to send the response.
The best way to debug this is to use a network sniffer (for eg: NetworkMonitor) which ships with Windows NT (if you are running on NT platforms). Or you can use free sniffers which are available on the web.
baboori
http://dotnetslackers.com/community/blogs/ruslantrifonov/archive/2006/11/30/_2200_How-To_2200_-Series_3A00_-Detect-network-connection-in-Compact-Framework.aspx
Anyway, you need to do a request.Abort() before closing the response. But you have to do it after you are done using the stream;
This works:
Thanks for helping!
public void GetWebStream()
{
{
request.Timeout = 5000;
HttpWebResponse resp =
byte[] data = new byte[1000000]; //dummy read routine
int remaining = data.Length;
int offset = 0;
while (remaining > 0)
{
if (read <= 0)
throw new EndOfStreamException
offset += read;
Console.WriteLine("Stream Read over -- close response");
request.Abort(); // <=== MAGIC PART
if (resp != null)
}
catch (Exception e)
{
httpStream = null;
return;
pnp
I can successfully and repeatedly make a single request, but I can't close the response.
try
{
request.KeepAlive = false;
request.Timeout = 5000;
HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
Console.WriteLine("response: {0}",
if (resp != null)
{
httpStream = null;
Raguvind
I was going to try to put the HttpWebRequest/Response in it's own object/instance. Maybe Disposing of the object will take the HttpWebRequest with it. It's a stretch.
I'm surprised there are no one has posted how to do this. If you google "HttpWebRequest close hangs", others have seem this. It's seems to be a pretty core method of getting data over a network. Anyway, I can't think of another way to do it right now, so I'll keep trying the HttpWebRequest path.
lbc06
Chaitanya15
iDeNoh
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse response = HttpWebResponse)request.GetResponse();
Stream testStream = request.GetRequestStream();
// do something useful with testStream
testStream.Flush();
testStream.Close();
response.Close();
response = null;
request = null;
CostasT
kicks_joy_darkness
I think I've made some progress, even though it's still pretty screwed up.
I did notice trying to make the 3rd request doesn't hang forever. It used the Timeout property set to a 100 second timeout. So there are 2 open requests, and it can't make the third one. So you apparently need to close one first.
But if you use the HttpWebResponse.Close method, it will hang indefinitely. I just need to figure out how to close the response so I can make another request.