HttpClient.PostAsync 方法

定义

以异步操作将 POST 请求发送给指定 URI。Send a POST request to the specified Uri as an asynchronous operation.

重载

PostAsync(String, HttpContent, CancellationToken)

用以异步操作的取消标记发送 POST 请求。Send a POST request with a cancellation token as an asynchronous operation.

PostAsync(Uri, HttpContent, CancellationToken)

用以异步操作的取消标记发送 POST 请求。Send a POST request with a cancellation token as an asynchronous operation.

PostAsync(String, HttpContent)

以异步操作将 POST 请求发送给指定 URI。Send a POST request to the specified Uri as an asynchronous operation.

PostAsync(Uri, HttpContent)

以异步操作将 POST 请求发送给指定 URI。Send a POST request to the specified Uri as an asynchronous operation.

注解

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

PostAsync(String, HttpContent, CancellationToken)

用以异步操作的取消标记发送 POST 请求。Send a POST request with a cancellation token as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ PostAsync(System::String ^ requestUri, System::Net::Http::HttpContent ^ content, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> PostAsync (string requestUri, System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> PostAsync (string? requestUri, System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken);
member this.PostAsync : string * System.Net.Http.HttpContent * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function PostAsync (requestUri As String, content As HttpContent, cancellationToken As CancellationToken) As Task(Of HttpResponseMessage)

参数

requestUri
String

请求发送到的 URI。The Uri the request is sent to.

content
HttpContent

发送到服务器的 HTTP 请求内容。The HTTP request content sent to the server.

cancellationToken
CancellationToken

可由其他对象或线程用以接收取消通知的取消标记。A cancellation token that can be used by other objects or threads to receive notice of cancellation.

返回

Task<HttpResponseMessage>

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

例外

requestUri 必须为绝对 URI 或必须设置 BaseAddressThe requestUri must be an absolute URI or BaseAddress must be set.

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

仅限 .NET Core 和 .NET 5.0 及更高版本:请求因超时而失败。.NET Core and .NET 5.0 and later only: The request failed due to timeout.

注解

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

备注

在超时情况下,不同的 .NET 实现会引发不同的异常。In case of timeout, different exceptions are thrown on different .NET implementations.

适用于

PostAsync(Uri, HttpContent, CancellationToken)

用以异步操作的取消标记发送 POST 请求。Send a POST request with a cancellation token as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ PostAsync(Uri ^ requestUri, System::Net::Http::HttpContent ^ content, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> PostAsync (Uri requestUri, System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> PostAsync (Uri? requestUri, System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken);
member this.PostAsync : Uri * System.Net.Http.HttpContent * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function PostAsync (requestUri As Uri, content As HttpContent, cancellationToken As CancellationToken) As Task(Of HttpResponseMessage)

参数

requestUri
Uri

请求发送到的 URI。The Uri the request is sent to.

content
HttpContent

发送到服务器的 HTTP 请求内容。The HTTP request content sent to the server.

cancellationToken
CancellationToken

可由其他对象或线程用以接收取消通知的取消标记。A cancellation token that can be used by other objects or threads to receive notice of cancellation.

返回

Task<HttpResponseMessage>

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

例外

requestUri 必须为绝对 URI 或必须设置 BaseAddressThe requestUri must be an absolute URI or BaseAddress must be set.

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

仅限 .NET Core 和 .NET 5.0 及更高版本:请求因超时而失败。.NET Core and .NET 5.0 and later only: The request failed due to timeout.

注解

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

备注

在超时情况下,不同的 .NET 实现会引发不同的异常。In case of timeout, different exceptions are thrown on different .NET implementations.

适用于

PostAsync(String, HttpContent)

以异步操作将 POST 请求发送给指定 URI。Send a POST request to the specified Uri as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ PostAsync(System::String ^ requestUri, System::Net::Http::HttpContent ^ content);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> PostAsync (string requestUri, System.Net.Http.HttpContent content);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> PostAsync (string? requestUri, System.Net.Http.HttpContent content);
member this.PostAsync : string * System.Net.Http.HttpContent -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function PostAsync (requestUri As String, content As HttpContent) As Task(Of HttpResponseMessage)

参数

requestUri
String

请求发送到的 URI。The Uri the request is sent to.

content
HttpContent

发送到服务器的 HTTP 请求内容。The HTTP request content sent to the server.

返回

Task<HttpResponseMessage>

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

例外

requestUri 必须为绝对 URI 或必须设置 BaseAddressThe requestUri must be an absolute URI or BaseAddress must be set.

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

仅限 .NET Core 和 .NET 5.0 及更高版本:请求因超时而失败。.NET Core and .NET 5.0 and later only: The request failed due to timeout.

注解

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

备注

在超时情况下,不同的 .NET 实现会引发不同的异常。In case of timeout, different exceptions are thrown on different .NET implementations.

适用于

PostAsync(Uri, HttpContent)

以异步操作将 POST 请求发送给指定 URI。Send a POST request to the specified Uri as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::Http::HttpResponseMessage ^> ^ PostAsync(Uri ^ requestUri, System::Net::Http::HttpContent ^ content);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> PostAsync (Uri requestUri, System.Net.Http.HttpContent content);
public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> PostAsync (Uri? requestUri, System.Net.Http.HttpContent content);
member this.PostAsync : Uri * System.Net.Http.HttpContent -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function PostAsync (requestUri As Uri, content As HttpContent) As Task(Of HttpResponseMessage)

参数

requestUri
Uri

请求发送到的 URI。The Uri the request is sent to.

content
HttpContent

发送到服务器的 HTTP 请求内容。The HTTP request content sent to the server.

返回

Task<HttpResponseMessage>

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

例外

requestUri 必须为绝对 URI 或必须设置 BaseAddressThe requestUri must be an absolute URI or BaseAddress must be set.

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

仅限 .NET Core 和 .NET 5.0 及更高版本:请求因超时而失败。.NET Core and .NET 5.0 and later only: The request failed due to timeout.

注解

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

备注

在超时情况下,不同的 .NET 实现会引发不同的异常。In case of timeout, different exceptions are thrown on different .NET implementations.

适用于