HttpClient.Send 方法

定義

多載

Send(HttpRequestMessage)

使用指定的要求傳送 HTTP 要求。Sends an HTTP request with the specified request.

Send(HttpRequestMessage, HttpCompletionOption)

傳送 HTTP 要求。Sends an HTTP request.

Send(HttpRequestMessage, CancellationToken)

使用指定的要求和取消權杖來傳送 HTTP 要求。Sends an HTTP request with the specified request and cancellation token.

Send(HttpRequestMessage, HttpCompletionOption, CancellationToken)

使用指定的要求和取消權杖來傳送 HTTP 要求。Sends an HTTP request with the specified request, completion option and cancellation token.

Send(HttpRequestMessage)

使用指定的要求傳送 HTTP 要求。Sends an HTTP request with the specified request.

public:
 System::Net::Http::HttpResponseMessage ^ Send(System::Net::Http::HttpRequestMessage ^ request);
public System.Net.Http.HttpResponseMessage Send (System.Net.Http.HttpRequestMessage request);
override this.Send : System.Net.Http.HttpRequestMessage -> System.Net.Http.HttpResponseMessage
Public Function Send (request As HttpRequestMessage) As HttpResponseMessage

參數

request
HttpRequestMessage

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

傳回

HttpResponseMessage

HTTP 回應訊息。An HTTP response message.

例外狀況

requestnullThe request is null.

HTTP 版本為2.0 或更高版本,或者版本原則設定為 RequestVersionOrHigherThe HTTP version is 2.0 or higher or the version policy is set to RequestVersionOrHigher.

-或--or-

衍生自 HttpContent 的自訂類別不會覆寫 SerializeToStream(Stream, TransportContext, CancellationToken) 方法。The custom class derived from HttpContent does not override the SerializeToStream(Stream, TransportContext, CancellationToken) method.

-或--or-

自訂的 HttpMessageHandler 不會覆寫 Send(HttpRequestMessage, CancellationToken) 方法。The custom HttpMessageHandler does not override the Send(HttpRequestMessage, CancellationToken) method.

要求訊息已經透過 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, or server certificate validation.

如果 TaskCanceledException 例外狀況使 TimeoutException 成為巢狀:要求會因逾時而失敗。If the TaskCanceledException exception nests the TimeoutException: The request failed due to timeout.

適用於

Send(HttpRequestMessage, HttpCompletionOption)

傳送 HTTP 要求。Sends an HTTP request.

public:
 System::Net::Http::HttpResponseMessage ^ Send(System::Net::Http::HttpRequestMessage ^ request, System::Net::Http::HttpCompletionOption completionOption);
public System.Net.Http.HttpResponseMessage Send (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption);
override this.Send : System.Net.Http.HttpRequestMessage * System.Net.Http.HttpCompletionOption -> System.Net.Http.HttpResponseMessage
Public Function Send (request As HttpRequestMessage, completionOption As HttpCompletionOption) As HttpResponseMessage

參數

request
HttpRequestMessage

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

completionOption
HttpCompletionOption

指定作業應該完成的時間 (可取得回應時或讀取整個回應內容之後) 的其中一個列舉值。One of the enumeration values that specifies when the operation should complete (as soon as a response is available or after reading the response content).

傳回

HttpResponseMessage

HTTP 回應訊息。The HTTP response message.

例外狀況

requestnullThe request is null.

HTTP 版本為2.0 或更高版本,或者版本原則設定為 RequestVersionOrHigherThe HTTP version is 2.0 or higher or the version policy is set to RequestVersionOrHigher.

-或--or-

衍生自 HttpContent 的自訂類別不會覆寫 SerializeToStream(Stream, TransportContext, CancellationToken) 方法。The custom class derived from HttpContent does not override the SerializeToStream(Stream, TransportContext, CancellationToken) method.

-或--or-

自訂的 HttpMessageHandler 不會覆寫 Send(HttpRequestMessage, CancellationToken) 方法。The custom HttpMessageHandler does not override the Send(HttpRequestMessage, CancellationToken) method.

要求訊息已經透過 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, or server certificate validation.

如果 TaskCanceledException 例外狀況使 TimeoutException 成為巢狀:要求會因逾時而失敗。If the TaskCanceledException exception nests the TimeoutException: The request failed due to timeout.

適用於

Send(HttpRequestMessage, CancellationToken)

使用指定的要求和取消權杖來傳送 HTTP 要求。Sends an HTTP request with the specified request and cancellation token.

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

參數

request
HttpRequestMessage

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

cancellationToken
CancellationToken

用於取消作業的權杖。The token to cancel the operation.

傳回

HttpResponseMessage

HTTP 回應訊息。The HTTP response message.

例外狀況

requestnullThe request is null.

HTTP 版本為2.0 或更高版本,或者版本原則設定為 RequestVersionOrHigherThe HTTP version is 2.0 or higher or the version policy is set to RequestVersionOrHigher.

-或--or-

衍生自 HttpContent 的自訂類別不會覆寫 SerializeToStream(Stream, TransportContext, CancellationToken) 方法。The custom class derived from HttpContent does not override the SerializeToStream(Stream, TransportContext, CancellationToken) method.

-或--or-

自訂的 HttpMessageHandler 不會覆寫 Send(HttpRequestMessage, CancellationToken) 方法。The custom HttpMessageHandler does not override the Send(HttpRequestMessage, CancellationToken) method.

要求訊息已經透過 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, or server certificate validation.

已取消要求。The request was canceled.

-或--or-

如果 TaskCanceledException 例外狀況使 TimeoutException 成為巢狀:要求會因逾時而失敗。If the TaskCanceledException exception nests the TimeoutException: The request failed due to timeout.

適用於

Send(HttpRequestMessage, HttpCompletionOption, CancellationToken)

使用指定的要求和取消權杖來傳送 HTTP 要求。Sends an HTTP request with the specified request, completion option and cancellation token.

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

參數

request
HttpRequestMessage

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

completionOption
HttpCompletionOption

指定作業應該完成的時間 (可取得回應時或讀取整個回應內容之後) 的其中一個列舉值。One of the enumeration values that specifies when the operation should complete (as soon as a response is available or after reading the response content).

cancellationToken
CancellationToken

用於取消作業的權杖。The token to cancel the operation.

傳回

HttpResponseMessage

HTTP 回應訊息。The HTTP response message.

例外狀況

requestnullThe request is null.

HTTP 版本為2.0 或更高版本,或者版本原則設定為 RequestVersionOrHigherThe HTTP version is 2.0 or higher or the version policy is set to RequestVersionOrHigher.

-或--or-

衍生自 HttpContent 的自訂類別不會覆寫 SerializeToStream(Stream, TransportContext, CancellationToken) 方法。The custom class derived from HttpContent does not override the SerializeToStream(Stream, TransportContext, CancellationToken) method.

-或--or-

自訂的 HttpMessageHandler 不會覆寫 Send(HttpRequestMessage, CancellationToken) 方法。The custom HttpMessageHandler does not override the Send(HttpRequestMessage, CancellationToken) method.

要求訊息已經透過 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, or server certificate validation.

已取消要求。The request was canceled.

-或--or-

如果 TaskCanceledException 例外狀況使 TimeoutException 成為巢狀:要求會因逾時而失敗。If the TaskCanceledException exception nests the TimeoutException: The request failed due to timeout.

適用於