Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

HttpWebRequest::GetRequestStream Method (TransportContext%)

Gets a Stream object to use to write request data and outputs the TransportContext associated with the stream.

Namespace:  System.Net
Assembly:  System (in System.dll)
public:
Stream^ GetRequestStream(
	[OutAttribute] TransportContext^% context
)

Parameters

context
Type: System.Net::TransportContext%
The TransportContext for the Stream.

Return Value

Type: System.IO::Stream
A Stream to use to write request data.
ExceptionCondition
Exception

The GetRequestStream method was unable to obtain the Stream.

InvalidOperationException

The GetRequestStream method is called more than once.

-or-

TransferEncoding is set to a value and SendChunked is false.

NotSupportedException

The request cache validator indicated that the response for this request can be served from the cache; however, requests that write data must not use the cache. This exception can occur if you are using a custom cache validator that is incorrectly implemented.

ProtocolViolationException

The Method property is GET or HEAD.

-or-

KeepAlive is true, AllowWriteStreamBuffering is false, ContentLength is -1, SendChunked is false, and Method is POST or PUT.

WebException

Abort was previously called.

-or-

The time-out period for the request expired.

-or-

An error occurred while processing the request.

The GetRequestStream method returns a stream to use to send data for the HttpWebRequest and outputs the TransportContext associated with the stream. After the Stream object has been returned, you can send data with the HttpWebRequest by using the Stream::Write method.

Some applications that use integrated Windows authentication with extended protection may need to be able to query the transport layer used by HttpWebRequest in order to retrieve the channel binding token (CBT) from the underlying TLS channel. The GetRequestStream method provides access to this information for HTTP methods which have a request body (POST and PUT requests). This is only needed if the application is implementing its own authentication and needs access to the CBT.

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

You must call the 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.

NoteNote

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

NoteNote

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing.

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.