471,350 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

HttpWebRequest Hangs

The following code hangs at the GetRequestStream after a few loops of
succesful execution:
while (true)
{
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(new
Uri(strUri));

//add headers here
httpRequest.Method = "POST";
httpRequest.Referer = strReferer;
httpRequest.ContentType = "application/x-www-form-urlencoded";
etc.....

string strPostData = strPostData;
byte[] baData = Encoding.ASCII.GetBytes(strPostData);
request.ContentLength = baData.Length;

Stream newStream = request.GetRequestStream();
newStream.Write(baData, 0, baData.Length);
newStream.Close();

HttpWebResponse httpResponse = (HttpWebResponse)request.GetResponse();
Stream sStream = httpResponse.GetResponseStream()
}

The code works fine the first few times through the loop, but I'm
guessing there is something that needs to be cleeared which is not
getting done so it gets gummed up?

Jan 4 '06 #1
1 5205
Hello mw*****@gmail.com,
The following code hangs at the GetRequestStream after a few loops of
succesful execution:
while (true)
{
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(new
Uri(strUri));
//add headers here
httpRequest.Method = "POST";
httpRequest.Referer = strReferer;
httpRequest.ContentType = "application/x-www-form-urlencoded";
etc.....
string strPostData = strPostData;
byte[] baData = Encoding.ASCII.GetBytes(strPostData);
request.ContentLength = baData.Length;
Stream newStream = request.GetRequestStream();
newStream.Write(baData, 0, baData.Length);
newStream.Close();
HttpWebResponse httpResponse = (HttpWebResponse)request.GetResponse();
Stream sStream = httpResponse.GetResponseStream()
}
The code works fine the first few times through the loop, but I'm
guessing there is something that needs to be cleeared which is not
getting done so it gets gummed up?


You neither close your HttpWebResponse nor its response stream.

You should always use using-blocks or try/finally blocks for disposable types
(i.e. those that implement IDisposable) to avoid such resource leaks.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Jan 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Dan Battagin | last post: by
6 posts views Thread by RP | last post: by
1 post views Thread by ratnakarp | last post: by
reply views Thread by =?Utf-8?B?RGFuaQ==?= | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.