473,624 Members | 2,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reusing HttpWebRequest. GetRequestStrea m

Dan

I'm experimenting with HttpWebRequest. After I've created a request:

m_request = (HttpWebRequest ) WebRequest.Crea te(uri);

I'd like to repeatedly send requests to the URI, as follows:

public void SendRequest(str ing body)
{
StreamWriter stream = new
StreamWriter(m_ request.GetRequ estStream(),Enc oding.ASCII);
stream.Write(bo dy);
stream.Close();
}

However, the second time I send the request I get the following exception:

An unhandled exception of type 'System.Argumen tException' occurred in
mscorlib.dll
Additional information: Stream was not writable.

Does anybody know why that happens?
Thanks...

Dan
Nov 18 '05 #1
3 7859
Dan
That is part of the HTTP protocol. After a Web request is made, the underlying connection is closed unless the client specifies to keep it open for a period of time. You can request the connection to stay open by setting the Connection property of the HttpWebRequest object to "Keep-alive"

Tu-Thac

----- Dan wrote: ----
I'm experimenting with HttpWebRequest. After I've created a request

m_request = (HttpWebRequest ) WebRequest.Crea te(uri)

I'd like to repeatedly send requests to the URI, as follows

public void SendRequest(str ing body

StreamWriter stream = ne
StreamWriter(m_ request.GetRequ estStream(),Enc oding.ASCII)
stream.Write(bo dy)
stream.Close()
However, the second time I send the request I get the following exception

An unhandled exception of type 'System.Argumen tException' occurred i
mscorlib.dl
Additional information: Stream was not writable

Does anybody know why that happens
Thanks..

Da

Nov 18 '05 #2
Dan
Thanks. However, when I set the connection property to "Keep-Alive", I got
the following exception: "Keep-Alive and Close may not be set with this
property."

I also tried setting the KeepAlive property to true, which made no
difference: I still got the "Stream was not writable" exception.

"Tu-Thach" <tu*****@antisp am.ongtech.com> wrote in message
news:B2******** *************** ***********@mic rosoft.com...
Dan,
That is part of the HTTP protocol. After a Web request is made, the underlying connection is closed unless the client specifies to keep it open
for a period of time. You can request the connection to stay open by
setting the Connection property of the HttpWebRequest object to
"Keep-alive".
Tu-Thach

----- Dan wrote: -----
I'm experimenting with HttpWebRequest. After I've created a request:

m_request = (HttpWebRequest ) WebRequest.Crea te(uri);

I'd like to repeatedly send requests to the URI, as follows:

public void SendRequest(str ing body)
{
StreamWriter stream = new
StreamWriter(m_ request.GetRequ estStream(),Enc oding.ASCII);
stream.Write(bo dy);
stream.Close();
}

However, the second time I send the request I get the following exception:
An unhandled exception of type 'System.Argumen tException' occurred in
mscorlib.dll
Additional information: Stream was not writable.

Does anybody know why that happens?
Thanks...

Dan

Nov 18 '05 #3
Dan wrote:
I'm experimenting with HttpWebRequest. After I've created a request:

m_request = (HttpWebRequest ) WebRequest.Crea te(uri);

I'd like to repeatedly send requests to the URI, as follows:

public void SendRequest(str ing body)
{
StreamWriter stream = new
StreamWriter(m_ request.GetRequ estStream(),Enc oding.ASCII);
stream.Write(bo dy);
stream.Close();
}

However, the second time I send the request I get the following
exception:

An unhandled exception of type 'System.Argumen tException' occurred in
mscorlib.dll
Additional information: Stream was not writable.


I don't think its possible to reuse the request stream. Instead, just create
a new (Http)WebReques t instance.

Cheers,
--
Joerg Jooss
jo*********@gmx .net

Nov 18 '05 #4

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

Similar topics

9
8168
by: Mike Cronin via DotNetMonster.com | last post by:
Hi there, Can anyone tell me what level of encryption is used when making an HTTPS POST request through an instance of the System.Net.HttpWebRequest object? Thanks much in advance! Mike Cronin Data On Call - Programmer
2
2535
by: Matt | last post by:
I am having trouble with the HttpWebRequest.GetRequestStream method. I am posting data to my web server running NT4 iis4 using a loop. So every time the loop executes I want it to post data to my web page. It work the first 2 times the loop iterates, but on the third time around it gives me a timout error. The line it gives me an error on is: --Stream newStream = myRequest.GetRequestStream();--
3
15741
by: ME | last post by:
Hi; I am getting "Unhandled Exception: System.Net.WebException: The remote server returned an erro r: (401) Unauthorized." when I am trying to get a page via post. Code follows...
3
9883
by: Jason | last post by:
I'm having a hard time getting a call to HttpWebRequest's GetRequestSteam to work. Each time I try to run it, I get the following error: The underlying connection was closed: Unable to connect to the remote server. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more
0
1445
by: a_newcomb | last post by:
I have an application which polls and connects to a webserver on a background thread. When the application is supposed to exit, I call abort on the HttpWebRequest object. I have observed that when the PDT has no network connections ( i.e. configured for dhcp on the wireless interface, and the wireless settings aren't configured ), and the HttpWebRequest is blocking on GetRequestStream, abort doesn't throw an exception and the...
1
2357
by: Dave Brown | last post by:
I am attempting to post to a url (https://FakeURL/logon.asp) using the HttpWebRequest class. The response for a succesful post will contain the html for the logon user's default page. We've accomplished this in the past utilizing the ServerXMLHTTP object. When I try an equivalent? post utilizing the HttpWebRequest class, the response contains the html for logon.asp (the same page that was posted to), which indicates to me that in some...
8
3944
by: Dave Brown | last post by:
I am attempting to post to a url (https://FakeURL/logon.asp) using the HttpWebRequest class. The response for a succesful post will contain the html for the logon user's default page. We've accomplished this in the past utilizing the ServerXMLHTTP object. When I try an equivalent? post utilizing the HttpWebRequest class, the response contains the html for logon.asp (the same page that was posted to), which indicates to me that in some...
4
12698
by: Natalia | last post by:
Hello, I need to provide the ability to post file and some form elements via our website (asp.net) to the third party website (asp page). On http://aspalliance.com/236#Page4 - I found great advices but still having troubles... it might some obvious error that I am making but I just dont see it. ==================FIRST - Webclient=================================
0
2566
by: joshblair | last post by:
Hello, I am trying to post XML documents to a third party using the HttpWebRequest. This URL uses HTTPS (SSL) but I don't have a client certificate to deal with. Apparently they are using WebMethods as the platform that receives these postings. I don't have any experience with that technology. The sample below is the from test app that I put together to post the XML (cXML Order Requests) documents. These documents, at least my
0
8242
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8177
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8681
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8341
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
5570
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.