473,574 Members | 3,118 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpWebRequest Hangs

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

//add headers here
httpRequest.Met hod = "POST";
httpRequest.Ref erer = strReferer;
httpRequest.Con tentType = "applicatio n/x-www-form-urlencoded";
etc.....

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

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

HttpWebResponse httpResponse = (HttpWebRespons e)request.GetRe sponse();
Stream sStream = httpResponse.Ge tResponseStream ()
}

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 5483
Hello mw*****@gmail.c om,
The following code hangs at the GetRequestStrea m after a few loops of
succesful execution:
while (true)
{
HttpWebRequest httpRequest = (HttpWebRequest )WebRequest.Cre ate(new
Uri(strUri));
//add headers here
httpRequest.Met hod = "POST";
httpRequest.Ref erer = strReferer;
httpRequest.Con tentType = "applicatio n/x-www-form-urlencoded";
etc.....
string strPostData = strPostData;
byte[] baData = Encoding.ASCII. GetBytes(strPos tData);
request.Content Length = baData.Length;
Stream newStream = request.GetRequ estStream();
newStream.Write (baData, 0, baData.Length);
newStream.Close ();
HttpWebResponse httpResponse = (HttpWebRespons e)request.GetRe sponse();
Stream sStream = httpResponse.Ge tResponseStream ()
}
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********@joer gjooss.de
Jan 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
12310
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 threads from the ThreadPool. However, eventually (relatively quickly) there become fewer and fewer available worker threads in the pool, until there...
1
1536
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 HTTPWebRequest, and everthing goes fine, until the server responds with a "207 MULTISTATUS" response type - at this point, the program just hangs...
0
2912
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 same machine (for dev and testing). Here is the C# code snippet: 1 string clientAddr = "http://127.0.0.1:22225/"; 2 try 3 { 4 webreq =...
6
1563
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 SBS2003 running ISA2K as a proxy and .net 1.1 it basically hangs and times out. Here is the code snippet. Any ideas? ISA is configured in Integrated...
1
4701
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 list has a url (desclink) property too. i do httpwebrequest again for these url's with contenttype as "POST". some how i dont understand the...
1
3250
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 code hangs. This same code works in my DEV environment - I get the repsonse almost instantly. IIS appears to be setup the same on each box. The error...
4
3353
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 gets hanged. Even no error message is displayed. HttpWebRequest req =
4
4271
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 gets hanged. Even no error message is displayed. HttpWebRequest req =
0
1455
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 certificate, WebRequest request, int certificateProblem) { return true; }
0
7841
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8101
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8271
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7858
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8137
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5654
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5335
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3793
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.