Alex Rivera | Logout

how to read httpWebRequest's request stream in c#, i got error" the stream is not readable"?

Asked 2010-02-15T03:41:14.797
12

I want to read the request stream from a custom HttpWebRequest class that inherits from HttpWebRequest and I have tried to read the request stream in different stages but still not sure how to achieve that in the class.

This custom HttpWebRequest is used to serialize a soap message and I want to know what request has been sent in string format. I also implemented custom HttpRequestCreator, HttpWebResponse but still can't find a place/stage from which I can read the request stream.

If i output everything in a MemoryStream then copy the content to request stream, anyone knows which stage I can do it? In the constructor, BeginGetRequestStream, EndGetRequestStream or GetRequestStream?

Edit
Report

1 Answer

11

Your question is unclear.

If you're trying to read an HttpWebRequest's request stream after other code has written to the stream (a POST request), it's not possible. (The stream is sent directly to the server and is not stored in memory)

Instead, you'll need to expose your own MemoryStream, then write it to the HttpWebRequest's request stream wen you're ready to send the request.

answered 2010-02-15T03:49:09.070

Your Answer