HttpClient.GetByteArrayAsync Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Send a GET request to the specified Uri and return the response body as a byte array in an asynchronous operation.
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) |
Sends a GET request to the specified Uri and return the response body as a byte array in an asynchronous operation. |
GetByteArrayAsync(Uri, CancellationToken) |
Send a GET request to the specified Uri and return the response body as a byte array in an asynchronous operation. |
The operation will not block.
- Source:
- HttpClient.cs
- Source:
- HttpClient.cs
- Source:
- HttpClient.cs
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
The task object representing the asynchronous operation.
Exceptions
The requestUri
must be an absolute URI or BaseAddress must be set.
The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout.
.NET Core and .NET 5 and later only: The request failed due to timeout.
The provided request URI is not valid relative or absolute URI.
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.
- HttpRequestException is thrown on all applicable .NET Framework versions.
- TaskCanceledException without any inner exception is thrown on all applicable .NET Core versions.
- TaskCanceledException that nests a TimeoutException is thrown on .NET 5 and later versions.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
- Source:
- HttpClient.cs
- Source:
- HttpClient.cs
- Source:
- HttpClient.cs
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
The task object representing the asynchronous operation.
Exceptions
The requestUri
must be an absolute URI or BaseAddress must be set.
The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation (or timeout for .NET Framework only).
.NET Core and .NET 5 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 a timeout:
- .NET Framework throws a HttpRequestException.
- .NET Core throws a TaskCanceledException without any inner exception.
- .NET 5 and later versions throw a TaskCanceledException that nests a TimeoutException.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
- Source:
- HttpClient.cs
- Source:
- HttpClient.cs
- Source:
- HttpClient.cs
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, 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
The Uri the request is sent to.
- cancellationToken
- CancellationToken
The cancellation token to cancel the operation.
Returns
The task object representing the asynchronous operation.
Exceptions
The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation (or timeout for .NET Framework only).
.NET Core and .NET 5 and later only: The request failed due to timeout.
The provided request URI is not valid relative or absolute URI.
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 the whole response body is read.
Note
In case of a timeout:
- .NET Framework throws a HttpRequestException.
- .NET Core throws a TaskCanceledException without any inner exception.
- .NET 5 and later versions throw a TaskCanceledException that nests a TimeoutException.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | 5, 6, 7, 8, 9 |
- Source:
- HttpClient.cs
- Source:
- HttpClient.cs
- Source:
- HttpClient.cs
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, 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
The Uri the request is sent to.
- cancellationToken
- CancellationToken
The cancellation token to cancel the operation.
Returns
The task object representing the asynchronous operation.
Exceptions
The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation (or timeout for .NET Framework only).
.NET Core and .NET 5 and later only: The request failed due to timeout.
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 the whole response body is read.
Note
In case of a timeout:
- .NET Framework throws a HttpRequestException.
- .NET Core throws a TaskCanceledException without any inner exception.
- .NET 5 and later versions throw a TaskCanceledException that nests a TimeoutException.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | 5, 6, 7, 8, 9 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: