İngilizce dilinde oku Düzenle

Aracılığıyla paylaş


HttpClient.GetAsync Method

Definition

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 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)

Source:
HttpClient.cs
Source:
HttpClient.cs
Source:
HttpClient.cs

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

C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(string requestUri);
C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(string? requestUri);

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 doesn't block. The returned Task<TResult> object will complete after the whole response (including content) is read. The behavior is the same as if ResponseContentRead has been explicitly specified.

Not

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

Applies to

.NET 10 ve diğer sürümler
Ürün Sürümler
.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, 10
.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

GetAsync(Uri)

Source:
HttpClient.cs
Source:
HttpClient.cs
Source:
HttpClient.cs

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

C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(Uri requestUri);
C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(Uri? requestUri);

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.

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

Remarks

This operation doesn't block. The returned Task<TResult> object will complete after the whole response (including content) is read. The behavior is the same as if ResponseContentRead has been explicitly specified.

Not

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

Applies to

.NET 10 ve diğer sürümler
Ürün Sürümler
.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, 10
.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

GetAsync(String, HttpCompletionOption)

Source:
HttpClient.cs
Source:
HttpClient.cs
Source:
HttpClient.cs

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

C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(string requestUri, System.Net.Http.HttpCompletionOption completionOption);
C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(string? requestUri, System.Net.Http.HttpCompletionOption completionOption);

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

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 doesn't 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.

Not

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

Applies to

.NET 10 ve diğer sürümler
Ürün Sürümler
.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, 10
.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

GetAsync(String, CancellationToken)

Source:
HttpClient.cs
Source:
HttpClient.cs
Source:
HttpClient.cs

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

C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(string requestUri, System.Threading.CancellationToken cancellationToken);
C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(string? requestUri, System.Threading.CancellationToken cancellationToken);

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

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.

The provided request URI is not valid relative or absolute URI.

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

-or-

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

Remarks

This operation doesn't block. The returned Task<TResult> object will complete after the whole response (including content) is read. The behavior is the same as if ResponseContentRead has been explicitly specified.

Not

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

Applies to

.NET 10 ve diğer sürümler
Ürün Sürümler
.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, 10
.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

GetAsync(Uri, HttpCompletionOption)

Source:
HttpClient.cs
Source:
HttpClient.cs
Source:
HttpClient.cs

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

C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(Uri requestUri, System.Net.Http.HttpCompletionOption completionOption);
C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(Uri? requestUri, System.Net.Http.HttpCompletionOption completionOption);

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

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.

Remarks

This operation doesn't 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.

Not

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

Applies to

.NET 10 ve diğer sürümler
Ürün Sürümler
.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, 10
.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

GetAsync(Uri, CancellationToken)

Source:
HttpClient.cs
Source:
HttpClient.cs
Source:
HttpClient.cs

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

C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(Uri requestUri, System.Threading.CancellationToken cancellationToken);
C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(Uri? requestUri, System.Threading.CancellationToken cancellationToken);

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

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.

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

-or-

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

Remarks

This operation doesn't block. The returned Task<TResult> object will complete after the whole response (including content) is read. The behavior is the same as if ResponseContentRead has been explicitly specified.

Not

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

Applies to

.NET 10 ve diğer sürümler
Ürün Sürümler
.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, 10
.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

GetAsync(String, HttpCompletionOption, CancellationToken)

Source:
HttpClient.cs
Source:
HttpClient.cs
Source:
HttpClient.cs

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

C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(string requestUri, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken);
C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(string? requestUri, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken);

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

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.

The provided request URI is not valid relative or absolute URI.

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

-or-

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

Remarks

This operation doesn't 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.

Not

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

Applies to

.NET 10 ve diğer sürümler
Ürün Sürümler
.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, 10
.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

GetAsync(Uri, HttpCompletionOption, CancellationToken)

Source:
HttpClient.cs
Source:
HttpClient.cs
Source:
HttpClient.cs

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

C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(Uri requestUri, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken);
C#
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> GetAsync(Uri? requestUri, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken);

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

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.

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

-or-

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

Remarks

This operation doesn't 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.

Not

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

Applies to

.NET 10 ve diğer sürümler
Ürün Sürümler
.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, 10
.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