473,325 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Reusing HttpWebRequest.GetRequestStream

Dan

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

m_request = (HttpWebRequest) WebRequest.Create(uri);

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

public void SendRequest(string body)
{
StreamWriter stream = new
StreamWriter(m_request.GetRequestStream(),Encoding .ASCII);
stream.Write(body);
stream.Close();
}

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

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

Does anybody know why that happens?
Thanks...

Dan
Nov 18 '05 #1
3 7810
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.Create(uri)

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

public void SendRequest(string body

StreamWriter stream = ne
StreamWriter(m_request.GetRequestStream(),Encoding .ASCII)
stream.Write(body)
stream.Close()
However, the second time I send the request I get the following exception

An unhandled exception of type 'System.ArgumentException' 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*****@antispam.ongtech.com> wrote in message
news:B2**********************************@microsof t.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.Create(uri);

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

public void SendRequest(string body)
{
StreamWriter stream = new
StreamWriter(m_request.GetRequestStream(),Encoding .ASCII);
stream.Write(body);
stream.Close();
}

However, the second time I send the request I get the following exception:
An unhandled exception of type 'System.ArgumentException' 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.Create(uri);

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

public void SendRequest(string body)
{
StreamWriter stream = new
StreamWriter(m_request.GetRequestStream(),Encoding .ASCII);
stream.Write(body);
stream.Close();
}

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

An unhandled exception of type 'System.ArgumentException' 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)WebRequest 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
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...
2
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...
3
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
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...
0
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...
1
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...
8
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...
4
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...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.