HttpContent.ReadAsStreamAsync Method

Definition

Serializes the HTTP content and returns a stream that represents the content.

Overloads

ReadAsStreamAsync()

Serialize the HTTP content and return a stream that represents the content as an asynchronous operation.

ReadAsStreamAsync(CancellationToken)

Serialize the HTTP content and return a stream that represents the content as an asynchronous operation.

Remarks

Note that this method will internally buffer the content unless CreateContentReadStreamAsync() has been implemented to do otherwise.

ReadAsStreamAsync()

Source:
HttpContent.cs
Source:
HttpContent.cs
Source:
HttpContent.cs

Serialize the HTTP content and return a stream that represents the content as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::IO::Stream ^> ^ ReadAsStreamAsync();
public System.Threading.Tasks.Task<System.IO.Stream> ReadAsStreamAsync ();
member this.ReadAsStreamAsync : unit -> System.Threading.Tasks.Task<System.IO.Stream>
Public Function ReadAsStreamAsync () As Task(Of Stream)

Returns

The task object representing the asynchronous operation.

Remarks

This operation will not block. The returned Task<TResult> object will complete after all of the stream that represents content has been read.

Once the operation completes, the Result property on the returned task object contains the stream that represents the HTTP content. The returned stream can then be used to read the content using various stream APIs.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by ReadAsStream().

Applies to

ReadAsStreamAsync(CancellationToken)

Source:
HttpContent.cs
Source:
HttpContent.cs
Source:
HttpContent.cs

Serialize the HTTP content and return a stream that represents the content as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::IO::Stream ^> ^ ReadAsStreamAsync(System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.IO.Stream> ReadAsStreamAsync (System.Threading.CancellationToken cancellationToken);
member this.ReadAsStreamAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.IO.Stream>
Public Function ReadAsStreamAsync (cancellationToken As CancellationToken) As Task(Of Stream)

Parameters

cancellationToken
CancellationToken

The cancellation token to cancel the operation.

Returns

The task object representing the asynchronous operation.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

This operation will not block. The returned Task<TResult> object will complete after all of the stream that represents content has been read (unless CreateContentReadStream(CancellationToken) has been implemented to do otherwise). For example, when using HttpClient, a method such as SendAsync returns a class derived from HttpContent that conditionally buffers based on what's passed for the completionOption parameter.

Once the operation completes, the Result property on the returned task object contains the stream that represents the HTTP content. The returned stream can then be used to read the content using various stream APIs.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by ReadAsStream().

Applies to