HttpClient.GetByteArrayAsync Method

Definition

Send a GET request to the specified Uri and return the response body as a byte array in an asynchronous operation.

Overloads

GetByteArrayAsync(String)

Sends a GET request to the specified Uri and return the response body as a byte array in an asynchronous operation.

GetByteArrayAsync(Uri)

Send a GET request to the specified Uri and return the response body as a byte array in an asynchronous operation.

GetByteArrayAsync(String, CancellationToken)
GetByteArrayAsync(Uri, CancellationToken)

Remarks

The operation will not block.

GetByteArrayAsync(String)

Sends a GET request to the specified Uri and return the response body as a byte array in an asynchronous operation.

public:
 System::Threading::Tasks::Task<cli::array <System::Byte> ^> ^ GetByteArrayAsync(System::String ^ requestUri);
public System.Threading.Tasks.Task<byte[]> GetByteArrayAsync (string requestUri);
public System.Threading.Tasks.Task<byte[]> GetByteArrayAsync (string? requestUri);
member this.GetByteArrayAsync : string -> System.Threading.Tasks.Task<byte[]>
Public Function GetByteArrayAsync (requestUri As String) As Task(Of Byte())

Parameters

requestUri
String

The Uri the request is sent to.

Returns

Task<Byte[]>

The task object representing the asynchronous operation.

Exceptions

The requestUri is null.

The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout.

.NET Core and .NET 5.0 and later only: The request failed due to timeout.

Remarks

This operation will not block. The returned Task<TResult> object will complete after the whole response body is read.

Note

In case of timeout, different exceptions are thrown on different .NET implementations.

GetByteArrayAsync(Uri)

Send a GET request to the specified Uri and return the response body as a byte array in an asynchronous operation.

public:
 System::Threading::Tasks::Task<cli::array <System::Byte> ^> ^ GetByteArrayAsync(Uri ^ requestUri);
public System.Threading.Tasks.Task<byte[]> GetByteArrayAsync (Uri requestUri);
public System.Threading.Tasks.Task<byte[]> GetByteArrayAsync (Uri? requestUri);
member this.GetByteArrayAsync : Uri -> System.Threading.Tasks.Task<byte[]>
Public Function GetByteArrayAsync (requestUri As Uri) As Task(Of Byte())

Parameters

requestUri
Uri

The Uri the request is sent to.

Returns

Task<Byte[]>

The task object representing the asynchronous operation.

Exceptions

The requestUri is null.

The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout.

.NET Core and .NET 5.0 and later only: The request failed due to timeout.

Remarks

This operation will not block. The returned Task<TResult> object will complete after the whole response body is read.

Note

In case of timeout, different exceptions are thrown on different .NET implementations.

GetByteArrayAsync(String, CancellationToken)

public:
 System::Threading::Tasks::Task<cli::array <System::Byte> ^> ^ GetByteArrayAsync(System::String ^ requestUri, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<byte[]> GetByteArrayAsync (string? requestUri, System.Threading.CancellationToken cancellationToken);
member this.GetByteArrayAsync : string * System.Threading.CancellationToken -> System.Threading.Tasks.Task<byte[]>
Public Function GetByteArrayAsync (requestUri As String, cancellationToken As CancellationToken) As Task(Of Byte())

Parameters

requestUri
String
cancellationToken
CancellationToken

Returns

Task<Byte[]>

GetByteArrayAsync(Uri, CancellationToken)

public:
 System::Threading::Tasks::Task<cli::array <System::Byte> ^> ^ GetByteArrayAsync(Uri ^ requestUri, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<byte[]> GetByteArrayAsync (Uri? requestUri, System.Threading.CancellationToken cancellationToken);
member this.GetByteArrayAsync : Uri * System.Threading.CancellationToken -> System.Threading.Tasks.Task<byte[]>
Public Function GetByteArrayAsync (requestUri As Uri, cancellationToken As CancellationToken) As Task(Of Byte())

Parameters

requestUri
Uri
cancellationToken
CancellationToken

Returns

Task<Byte[]>

Applies to