HttpClient.SendAsync HttpClient.SendAsync HttpClient.SendAsync HttpClient.SendAsync Method

定义

以异步操作发送 HTTP 请求。Send an HTTP request as an asynchronous operation.

重载

SendAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken) SendAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken) SendAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken)

以异步操作发送 HTTP 请求。Send an HTTP request as an asynchronous operation.

SendAsync(HttpRequestMessage) SendAsync(HttpRequestMessage) SendAsync(HttpRequestMessage) SendAsync(HttpRequestMessage)

以异步操作发送 HTTP 请求。Send an HTTP request as an asynchronous operation.

SendAsync(HttpRequestMessage, HttpCompletionOption) SendAsync(HttpRequestMessage, HttpCompletionOption) SendAsync(HttpRequestMessage, HttpCompletionOption) SendAsync(HttpRequestMessage, HttpCompletionOption)

以异步操作发送 HTTP 请求。Send an HTTP request as an asynchronous operation.

SendAsync(HttpRequestMessage, CancellationToken) SendAsync(HttpRequestMessage, CancellationToken) SendAsync(HttpRequestMessage, CancellationToken)

以异步操作发送 HTTP 请求。Send an HTTP request as an asynchronous operation.

注解

不会阻止此操作。This operation will not block.

SendAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken) SendAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken) SendAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken)

以异步操作发送 HTTP 请求。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>

参数

request
HttpRequestMessage HttpRequestMessage HttpRequestMessage HttpRequestMessage

要发送的 HTTP 请求消息。The HTTP request message to send.

completionOption
HttpCompletionOption HttpCompletionOption HttpCompletionOption HttpCompletionOption

操作应完成时(在响应可利用或在读取整个响应内容之后)。When the operation should complete (as soon as a response is available or after reading the whole response content).

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

取消操作的取消标记。The cancellation token to cancel operation.

返回

表示异步操作的任务对象。The task object representing the asynchronous operation.

异常

请求消息已由 HttpClient 实例发送。The request message was already sent by the HttpClient instance.

由于基础问题(如网络连接性、DNS 失败、服务器证书验证或超时),请求失败。The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout.

注解

不会阻止此操作。This operation will not block. 具体取决于值completionOption参数,返回Task<TResult>对象便可立即响应可用或读取包含内容的整个响应。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.

SendAsync(HttpRequestMessage) SendAsync(HttpRequestMessage) SendAsync(HttpRequestMessage) SendAsync(HttpRequestMessage)

以异步操作发送 HTTP 请求。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)

参数

request
HttpRequestMessage HttpRequestMessage HttpRequestMessage HttpRequestMessage

要发送的 HTTP 请求消息。The HTTP request message to send.

返回

表示异步操作的任务对象。The task object representing the asynchronous operation.

异常

请求消息已由 HttpClient 实例发送。The request message was already sent by the HttpClient instance.

由于基础问题(如网络连接性、DNS 失败、服务器证书验证或超时),请求失败。The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout.

注解

不会阻止此操作。This operation will not block. 返回Task<TResult>读取包含内容的整个响应后,将完成对象。The returned Task<TResult> object will complete once the entire response including content is read.

SendAsync(HttpRequestMessage, HttpCompletionOption) SendAsync(HttpRequestMessage, HttpCompletionOption) SendAsync(HttpRequestMessage, HttpCompletionOption) SendAsync(HttpRequestMessage, HttpCompletionOption)

以异步操作发送 HTTP 请求。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)

参数

request
HttpRequestMessage HttpRequestMessage HttpRequestMessage HttpRequestMessage

要发送的 HTTP 请求消息。The HTTP request message to send.

completionOption
HttpCompletionOption HttpCompletionOption HttpCompletionOption HttpCompletionOption

操作应完成时(在响应可利用或在读取整个响应内容之后)。When the operation should complete (as soon as a response is available or after reading the whole response content).

返回

表示异步操作的任务对象。The task object representing the asynchronous operation.

异常

请求消息已由 HttpClient 实例发送。The request message was already sent by the HttpClient instance.

由于基础问题(如网络连接性、DNS 失败、服务器证书验证或超时),请求失败。The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout.

注解

不会阻止此操作。This operation will not block. 具体取决于值completionOption参数,返回Task<TResult>对象便可立即响应可用或读取包含内容的整个响应。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.

SendAsync(HttpRequestMessage, CancellationToken) SendAsync(HttpRequestMessage, CancellationToken) SendAsync(HttpRequestMessage, CancellationToken)

以异步操作发送 HTTP 请求。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>

参数

request
HttpRequestMessage HttpRequestMessage HttpRequestMessage HttpRequestMessage

要发送的 HTTP 请求消息。The HTTP request message to send.

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

取消操作的取消标记。The cancellation token to cancel operation.

返回

表示异步操作的任务对象。The task object representing the asynchronous operation.

异常

请求消息已由 HttpClient 实例发送。The request message was already sent by the HttpClient instance.

由于基础问题(如网络连接性、DNS 失败、服务器证书验证或超时),请求失败。The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout.

注解

不会阻止此操作。This operation will not block. 返回Task<TResult>读取包含内容的整个响应后,将完成对象。The returned Task<TResult> object will complete once the entire response including content is read.

适用于