System.Net.HttpWebRequest.GetRequestStream Method

Gets a System.IO.Stream object to use to write request data.


public override System.IO.Stream GetRequestStream ()


A System.IO.Stream to use to write request data.



The HttpWebRequest.Method property of the current instance is "GET" or "HEAD".


The HttpWebRequest.ContentLength property of the current instance is not set.


The HttpWebRequest.GetRequestStream method was called more than once.


No writeable stream is available.


HttpWebRequest.Abort was previously called.


The timeout period for the request expired.


An error occurred while processing the request.


The HttpWebRequest.GetRequestStream method returns a stream to use to send data for the System.Net.HttpWebRequest. After the System.IO.Stream object has been returned, you can send data with the System.Net.HttpWebRequest by using the System.IO.Stream.Write(Byte[], int, int) method.

If an application needs to set the value of the HttpWebRequest.ContentLength property, then this must be done before retrieving the stream.

You must call the System.IO.Stream.Close method to close the stream and release the connection for reuse. Failure to close the stream causes your application to run out of connections.


Your application cannot mix synchronous and asynchronous methods for a particular request. If you call the HttpWebRequest.GetRequestStream method, you must use the HttpWebRequest.GetResponse method to retrieve the response.


This member outputs trace information when you enable network tracing in your application. For more information, see [<topic://conUsingNetworkTracing>].


Namespace: System.Net
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0,,