473,471 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 5459
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dan Battagin | last post by:
Is there a known bug with the interaction between the HttpWebRequest and the ThreadPool? I current spawn several HttpWebRequest's using BeginGetResponse, and they work for a while, using worker...
1
by: Nick Jacobsen | last post by:
Hoping that someone else has either run into this, or can point me in the right direction to fix it. I am making an PROPFIND HTTP Request to a WebDav Mail server (hotmail,. to be specific) using...
0
by: Nathan | last post by:
This is a copy of a message at microsoft.public.dotnet.framework.clr: THE CODE: I'm using an HttpWebResponse object to send an HTTP POST to a Java server I have written and are running on the...
6
by: RP | last post by:
Hi all, I have some code that does a basic form post to an .aspx page submitting some XML in the body. This code used to work on my WIN2K server running .net 1.0 sp2. Now since I have upgraded to...
1
by: ratnakarp | last post by:
Hi, I'm new to httpwebrequest programming. I'm using httpwebrequest to pull the rss file with contenttype as "GET". it works fine. I get all the results and store all the values in the list. the...
1
by: sbrown | last post by:
I'm sending an HttpWebRequest to a BizTalk server. BizTalk receives and asyncronously processes correctly, but I never receive an http response. The last statement in the snippet below is where my...
4
by: Mahernoz | last post by:
Hi Friends, I have this code in a C# console application which calls a URL on my website(Asp.net/C#) with Querystrings. (I have also tried without querystrings). The problem is my program...
4
by: Mahernoz | last post by:
Hi Friends, I have this code in a C# console application which calls a URL on my website(Asp.net/C#) with Querystrings. (I have also tried without querystrings). The problem is my program...
0
by: =?Utf-8?B?RGFuaQ==?= | last post by:
Hi. I'm using this code to access an https service: public class AcceptAllCertificatePolicy : ICertificatePolicy { public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.