System.Net.HttpWebRequest.BeginGetRequestStream Method

Begins an asynchronous request for a System.IO.Stream object to use to write data.

Syntax

public override IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state)

Parameters

callback
The AsyncCallback delegate.
state
The state object for this request.

Returns

An IAsyncResult that references the asynchronous request.

Exceptions

TypeReason
InvalidOperationException

The stream is being used by a previous call to HttpWebRequest.BeginGetRequestStream(AsyncCallback, object) .

-or-

No writeable stream is available.

System.Net.ProtocolViolationException

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

-or-

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

System.Net.WebException

HttpWebRequest.Abort was previously called.

-or-

An error occurred while processing the request.

Remarks

The HttpWebRequest.BeginGetRequestStream(AsyncCallback, object) method starts an asynchronous request for a stream used to send data for the System.Net.HttpWebRequest. The asynchronous callback method uses the HttpWebRequest.EndGetRequestStream(IAsyncResult) method to return the actual stream.

The HttpWebRequest.BeginGetRequestStream(AsyncCallback, object) method requires some synchronous setup tasks to complete (DNS resolution, proxy detection, and TCP socket connection, for example) before this method becomes asynchronous. As a result, this method should never be called on a user interface (UI) thread because it might take considerable time (up to several minutes depending on network settings) to complete the initial synchronous setup tasks before an exception for an error is thrown or the method succeeds.

To learn more about the thread pool, see [<topic://cpconthreadpooling>].

Note:

Your application cannot mix synchronous and asynchronous methods for a particular request. If you call the HttpWebRequest.BeginGetRequestStream(AsyncCallback, object) method, you must use the HttpWebRequest.BeginGetResponse(AsyncCallback, object) 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