HttpMessageInvoker.SendAsync(HttpRequestMessage, CancellationToken) HttpMessageInvoker.SendAsync(HttpRequestMessage, CancellationToken) HttpMessageInvoker.SendAsync(HttpRequestMessage, CancellationToken) Method

定義

以非同步作業的方式,傳送 HTTP 要求。Send an HTTP request as an asynchronous operation.

public:
 virtual System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ SendAsync(System::Net::Http::HttpRequestMessage ^ request, System::Threading::CancellationToken cancellationToken);
public virtual System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken);
abstract member SendAsync : System.Net.Http.HttpRequestMessage * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
override this.SendAsync : System.Net.Http.HttpRequestMessage * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>

參數

request
HttpRequestMessage HttpRequestMessage HttpRequestMessage

要傳送的 HTTP 要求訊息。The HTTP request message to send.

cancellationToken
CancellationToken CancellationToken CancellationToken

用於取消作業的取消語彙基元。The cancellation token to cancel operation.

傳回

工作物件,表示非同步作業。The task object representing the asynchronous operation.

例外狀況

request 以前是 nullThe request was null.

備註

這項作業不會封鎖。This operation will not block. 只要讀取Task<TResult>包含內容的整個回應, 傳回的物件就會完成。The returned Task<TResult> object will complete once the entire response including content is read.

大部分連接至網站的應用程式會SendAsync HttpClient在類別上使用其中一種方法。Most applications that are connecting to a web site will use one of the SendAsync methods on the HttpClient class.

適用於