HttpContent.CopyTo(Stream, TransportContext, CancellationToken) Method

Definition

Serializes the HTTP content into a stream of bytes and copies it to stream.

C#
public void CopyTo (System.IO.Stream stream, System.Net.TransportContext? context, System.Threading.CancellationToken cancellationToken);

Parameters

stream
Stream

The target stream.

context
TransportContext

Information about the transport (for example, the channel binding token). This parameter may be null.

cancellationToken
CancellationToken

The cancellation token to cancel the operation.

Exceptions

The stream was null.

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

Remarks

This method uses SerializeToStream(Stream, TransportContext, CancellationToken) internally to serialize the content into the given stream. If the content has been previously buffered, for example, by calling LoadIntoBufferAsync(), the method will return the buffered content and not call the serialization method.

Applies to

Produkt Versjoner
.NET 5, 6, 7, 8, 9