System.Net.HttpWebRequest.GetRequestStream Method

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

Syntax

public override System.IO.Stream GetRequestStream ()

Returns

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

Exceptions

TypeReason
System.Net.ProtocolViolationException

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

-or-

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

InvalidOperationException

The HttpWebRequest.GetRequestStream method was called more than once.

-or-

No writeable stream is available.

System.Net.WebException

HttpWebRequest.Abort was previously called.

-or-

The timeout period for the request expired.

-or-

An error occurred while processing the request.

Remarks

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.

Note:

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.

Note:

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

Requirements

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