views:

109

answers:

1

By default HttpWebRequest has AllowWriteStreamBuffering set to true, which means that all data written to the request stream is buffered inside the object.

I'd like to access this buffer of data after it has been written, but can't seem to find any way to do so. I'm happy for it to fail if AllowWriteStreamBuffering is false.

Is there any way to do this, or is it not exposed anywhere?


As to why I want to do this: I'm writing an OAuth request signing class, and unfortunately the protocol requires any form-encoded body to be considered part of the signature. So I need to be able to access the body if it's a form encoded one.

A: 

AllowWriteStreamBuffering uses an internal mechanism. The buffer is not exposed to the caller. It allows scenarios where the initial request is redirected, or denied for authentication, in which case the WebRequest can autopost the data to the new endpoint, without having to fail the request and asking the caller to resubmit.

You should find a different way to get the stream. Maybe you can first buffer it into your own buffer (i.e MemoryStream). Do your necessary operations, then flush that stream onto the WebRequest's requestStream.

feroze