संपादित करें

इसके माध्यम से साझा किया गया


HttpClient.SendAsync Method

Definition

Send an HTTP request as an asynchronous operation.

Overloads

SendAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken)

Send an HTTP request as an asynchronous operation.

SendAsync(HttpRequestMessage)

Send an HTTP request as an asynchronous operation.

SendAsync(HttpRequestMessage, HttpCompletionOption)

Send an HTTP request as an asynchronous operation.

SendAsync(HttpRequestMessage, CancellationToken)

Send an HTTP request as an asynchronous operation.

Remarks

This operation will not block.

SendAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken)

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

Send an HTTP request as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ SendAsync(System::Net::Http::HttpRequestMessage ^ request, System::Net::Http::HttpCompletionOption completionOption, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> SendAsync (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken);
override this.SendAsync : System.Net.Http.HttpRequestMessage * System.Net.Http.HttpCompletionOption * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function SendAsync (request As HttpRequestMessage, completionOption As HttpCompletionOption, cancellationToken As CancellationToken) As Task(Of HttpResponseMessage)

Parameters

request
HttpRequestMessage

The HTTP request message to send.

completionOption
HttpCompletionOption

When the operation should complete (as soon as a response is available or after reading the whole response content).

cancellationToken
CancellationToken

The cancellation token to cancel operation.

Returns

The task object representing the asynchronous operation.

Exceptions

The request is null.

The request message was already sent by the HttpClient instance.

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 cancellation token was canceled. This exception is stored into the returned task.

Remarks

This operation will not block. Depending on the value of the completionOption parameter, the returned Task<TResult> object will complete as soon as a response is available or the entire response including content is read.

Note

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

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Send(HttpRequestMessage, HttpCompletionOption).

Applies to

SendAsync(HttpRequestMessage)

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

Send an HTTP request as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ SendAsync(System::Net::Http::HttpRequestMessage ^ request);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> SendAsync (System.Net.Http.HttpRequestMessage request);
override this.SendAsync : System.Net.Http.HttpRequestMessage -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function SendAsync (request As HttpRequestMessage) As Task(Of HttpResponseMessage)

Parameters

request
HttpRequestMessage

The HTTP request message to send.

Returns

The task object representing the asynchronous operation.

Exceptions

The request is null.

The request message was already sent by the HttpClient instance.

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 will not block. The returned Task<TResult> object will complete once the entire response including content is read. The behavior is the same as if ResponseContentRead has been explicitly specified.

Note

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

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Send(HttpRequestMessage).

Applies to

SendAsync(HttpRequestMessage, HttpCompletionOption)

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

Send an HTTP request as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ SendAsync(System::Net::Http::HttpRequestMessage ^ request, System::Net::Http::HttpCompletionOption completionOption);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> SendAsync (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption);
override this.SendAsync : System.Net.Http.HttpRequestMessage * System.Net.Http.HttpCompletionOption -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function SendAsync (request As HttpRequestMessage, completionOption As HttpCompletionOption) As Task(Of HttpResponseMessage)

Parameters

request
HttpRequestMessage

The HTTP request message to send.

completionOption
HttpCompletionOption

When the operation should complete (as soon as a response is available or after reading the whole response content).

Returns

The task object representing the asynchronous operation.

Exceptions

The request is null.

The request message was already sent by the HttpClient instance.

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 will not block. Depending on the value of the completionOption parameter, the returned Task<TResult> object will complete as soon as a response is available or the entire response including content is read.

Note

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

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Send(HttpRequestMessage, HttpCompletionOption).

Applies to

SendAsync(HttpRequestMessage, CancellationToken)

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

Send an HTTP request as an asynchronous operation.

public:
 override System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ SendAsync(System::Net::Http::HttpRequestMessage ^ request, System::Threading::CancellationToken cancellationToken);
public override System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken);
override this.SendAsync : System.Net.Http.HttpRequestMessage * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Overrides Function SendAsync (request As HttpRequestMessage, cancellationToken As CancellationToken) As Task(Of HttpResponseMessage)

Parameters

request
HttpRequestMessage

The HTTP request message to send.

cancellationToken
CancellationToken

The cancellation token to cancel operation.

Returns

The task object representing the asynchronous operation.

Exceptions

The request is null.

The request message was already sent by the HttpClient instance.

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 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 once the entire response including content is read. The behavior is the same as if ResponseContentRead has been explicitly specified.

Note

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

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Send(HttpRequestMessage).

Applies to