HttpClient.GetAsync Method

Definition

Send a GET request to the specified Uri as an asynchronous operation.

Overloads

GetAsync(String)

Send a GET request to the specified Uri as an asynchronous operation.

GetAsync(Uri)

Send a GET request to the specified Uri as an asynchronous operation.

GetAsync(String, HttpCompletionOption)

Send a GET request to the specified Uri with an HTTP completion option as an asynchronous operation.

GetAsync(String, CancellationToken)

Send a GET request to the specified Uri with a cancellation token as an asynchronous operation.

GetAsync(Uri, HttpCompletionOption)

Send a GET request to the specified Uri with an HTTP completion option as an asynchronous operation.

GetAsync(Uri, CancellationToken)

Send a GET request to the specified Uri with a cancellation token as an asynchronous operation.

GetAsync(String, HttpCompletionOption, CancellationToken)

Send a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation.

GetAsync(Uri, HttpCompletionOption, CancellationToken)

Send a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation.

Remarks

The operation will not block.

GetAsync(String)

Send a GET request to the specified Uri as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ GetAsync(System::String ^ requestUri);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (string requestUri);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (string? requestUri);
member this.GetAsync : string -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function GetAsync (requestUri As String) As Task(Of HttpResponseMessage)

Parameters

requestUri
String

The Uri the request is sent to.

Returns

Task<HttpResponseMessage>

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.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 (including content) is read.

Note

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

Applies to

Product Introduced

GetAsync(Uri)

Send a GET request to the specified Uri as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ GetAsync(Uri ^ requestUri);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (Uri requestUri);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (Uri? requestUri);
member this.GetAsync : Uri -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function GetAsync (requestUri As Uri) As Task(Of HttpResponseMessage)

Parameters

requestUri
Uri

The Uri the request is sent to.

Returns

Task<HttpResponseMessage>

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.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 (including content) is read.

Note

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

Applies to

Product Introduced

GetAsync(String, HttpCompletionOption)

Send a GET request to the specified Uri with an HTTP completion option as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ GetAsync(System::String ^ requestUri, System::Net::Http::HttpCompletionOption completionOption);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (string requestUri, System.Net.Http.HttpCompletionOption completionOption);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (string? requestUri, System.Net.Http.HttpCompletionOption completionOption);
member this.GetAsync : string * System.Net.Http.HttpCompletionOption -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function GetAsync (requestUri As String, completionOption As HttpCompletionOption) As Task(Of HttpResponseMessage)

Parameters

requestUri
String

The Uri the request is sent to.

completionOption
HttpCompletionOption

An HTTP completion option value that indicates when the operation should be considered completed.

Returns

Task<HttpResponseMessage>

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.0 and later only: The request failed due to timeout.

Remarks

This operation will not block. The returned Task<TResult> object will complete based on the completionOption parameter after the part or all of the response (including content) is read.

Note

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

Applies to

Product Introduced

GetAsync(String, CancellationToken)

Send a GET request to the specified Uri with a cancellation token as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ GetAsync(System::String ^ requestUri, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (string requestUri, System.Threading.CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (string? requestUri, System.Threading.CancellationToken cancellationToken);
member this.GetAsync : string * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function GetAsync (requestUri As String, cancellationToken As CancellationToken) As Task(Of HttpResponseMessage)

Parameters

requestUri
String

The Uri the request is sent to.

cancellationToken
CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task<HttpResponseMessage>

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.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 (including content) is read.

Note

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

Applies to

Product Introduced

GetAsync(Uri, HttpCompletionOption)

Send a GET request to the specified Uri with an HTTP completion option as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ GetAsync(Uri ^ requestUri, System::Net::Http::HttpCompletionOption completionOption);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (Uri requestUri, System.Net.Http.HttpCompletionOption completionOption);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (Uri? requestUri, System.Net.Http.HttpCompletionOption completionOption);
member this.GetAsync : Uri * System.Net.Http.HttpCompletionOption -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function GetAsync (requestUri As Uri, completionOption As HttpCompletionOption) As Task(Of HttpResponseMessage)

Parameters

requestUri
Uri

The Uri the request is sent to.

completionOption
HttpCompletionOption

An HTTP completion option value that indicates when the operation should be considered completed.

Returns

Task<HttpResponseMessage>

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.0 and later only: The request failed due to timeout.

Remarks

This operation will not block. The returned Task<TResult> object will complete based on the completionOption parameter after the part or all of the response (including content) is read.

Note

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

Applies to

Product Introduced

GetAsync(Uri, CancellationToken)

Send a GET request to the specified Uri with a cancellation token as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ GetAsync(Uri ^ requestUri, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (Uri requestUri, System.Threading.CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (Uri? requestUri, System.Threading.CancellationToken cancellationToken);
member this.GetAsync : Uri * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function GetAsync (requestUri As Uri, cancellationToken As CancellationToken) As Task(Of HttpResponseMessage)

Parameters

requestUri
Uri

The Uri the request is sent to.

cancellationToken
CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task<HttpResponseMessage>

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.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 (including content) is read.

Note

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

Applies to

Product Introduced

GetAsync(String, HttpCompletionOption, CancellationToken)

Send a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ GetAsync(System::String ^ requestUri, System::Net::Http::HttpCompletionOption completionOption, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (string requestUri, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (string? requestUri, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken);
member this.GetAsync : string * System.Net.Http.HttpCompletionOption * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function GetAsync (requestUri As String, completionOption As HttpCompletionOption, cancellationToken As CancellationToken) As Task(Of HttpResponseMessage)

Parameters

requestUri
String

The Uri the request is sent to.

completionOption
HttpCompletionOption

An HTTP completion option value that indicates when the operation should be considered completed.

cancellationToken
CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task<HttpResponseMessage>

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.0 and later only: The request failed due to timeout.

Remarks

This operation will not block. The returned Task<TResult> object will complete based on the completionOption parameter after the part or all of the response (including content) is read.

Note

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

Applies to

Product Introduced

GetAsync(Uri, HttpCompletionOption, CancellationToken)

Send a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ GetAsync(Uri ^ requestUri, System::Net::Http::HttpCompletionOption completionOption, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (Uri requestUri, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync (Uri? requestUri, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken);
member this.GetAsync : Uri * System.Net.Http.HttpCompletionOption * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function GetAsync (requestUri As Uri, completionOption As HttpCompletionOption, cancellationToken As CancellationToken) As Task(Of HttpResponseMessage)

Parameters

requestUri
Uri

The Uri the request is sent to.

completionOption
HttpCompletionOption

An HTTP completion option value that indicates when the operation should be considered completed.

cancellationToken
CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task<HttpResponseMessage>

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.0 and later only: The request failed due to timeout.

Remarks

This operation will not block. The returned Task<TResult> object will complete based on the completionOption parameter after the part or all of the response (including content) is read.

Note

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

Applies to

Product Introduced