HttpClient.SendRequestAsync Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
SendRequestAsync(HttpRequestMessage) |
Send an HTTP request as an asynchronous operation. For programming guidance for the HttpClient class, and code examples, see the HttpClient conceptual topic. |
SendRequestAsync(HttpRequestMessage, HttpCompletionOption) |
Send an HTTP request with an HTTP completion option as an asynchronous operation. For programming guidance for the HttpClient class, and code examples, see the HttpClient conceptual topic. |
Send an HTTP request as an asynchronous operation. For programming guidance for the HttpClient class, and code examples, see the HttpClient conceptual topic.
public:
virtual IAsyncOperationWithProgress<HttpResponseMessage ^, HttpProgress> ^ SendRequestAsync(HttpRequestMessage ^ request) = SendRequestAsync;
/// [Windows.Foundation.Metadata.Overload("SendRequestAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress> SendRequestAsync(HttpRequestMessage const& request);
[Windows.Foundation.Metadata.Overload("SendRequestAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperationWithProgress<HttpResponseMessage,HttpProgress> SendRequestAsync(HttpRequestMessage request);
function sendRequestAsync(request)
Public Function SendRequestAsync (request As HttpRequestMessage) As IAsyncOperationWithProgress(Of HttpResponseMessage, HttpProgress)
Parameters
- request
- HttpRequestMessage
The HTTP request message to send.
Returns
The object representing the asynchronous operation.
- Attributes
Remarks
This operation will not block. The returned IAsyncOperationWithProgress (of HttpResponseMessage and HttpProgress) completes after the whole response (including content) is read.
The HttpRequestMessage passed in the request parameter allows the SendRequestAsync method to set headers on the request message as well as on the HTTP content to be sent. In contrast, the PostAsync and PutAsync methods only allow setting a more limited set of HTTP content headers.
Below are the exceptions that this function throws.
E_ILLEGAL_METHOD_CALL
The request message was already sent by the HttpClient instance.
Exception handling
You must write code to handle exceptions when you call this method. Exceptions can result from parameter validation errors, name resolutions failures, and network errors. Exceptions from network errors (loss of connectivity, connection failures, and HTTP server failures, for example) can happen at any time. These errors result in exceptions being thrown. If not handled by your app, an exception can cause your entire app to be terminated by the runtime. For more information on how to handle exceptions, see Handling exceptions in network apps and How to: Map HRESULTs and Exceptions.
See also
- HttpRequestMessage
- PostAsync(Uri, IHttpContent)
- PutAsync(Uri, IHttpContent)
- SendRequestAsync(HttpRequestMessage, HttpCompletionOption)
- HttpClient
Applies to
WinRT Build 26100 and other versions
Product | Versions |
---|---|
WinRT | Build 10240, Build 10586, Build 14383, Build 15063, Build 16299, Build 17134, Build 17763, Build 18362, Build 19041, Build 20348, Build 22000, Build 22621, Build 26100 |
Send an HTTP request with an HTTP completion option as an asynchronous operation. For programming guidance for the HttpClient class, and code examples, see the HttpClient conceptual topic.
public:
virtual IAsyncOperationWithProgress<HttpResponseMessage ^, HttpProgress> ^ SendRequestAsync(HttpRequestMessage ^ request, HttpCompletionOption completionOption) = SendRequestAsync;
/// [Windows.Foundation.Metadata.Overload("SendRequestWithOptionAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress> SendRequestAsync(HttpRequestMessage const& request, HttpCompletionOption const& completionOption);
[Windows.Foundation.Metadata.Overload("SendRequestWithOptionAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperationWithProgress<HttpResponseMessage,HttpProgress> SendRequestAsync(HttpRequestMessage request, HttpCompletionOption completionOption);
function sendRequestAsync(request, completionOption)
Public Function SendRequestAsync (request As HttpRequestMessage, completionOption As HttpCompletionOption) As IAsyncOperationWithProgress(Of HttpResponseMessage, HttpProgress)
Parameters
- request
- HttpRequestMessage
The HTTP request message to send.
- completionOption
- HttpCompletionOption
A value that indicates whether the HttpClient operation is considered completed when all of the response is read, or when just the headers are read.
Returns
The object representing the asynchronous operation.
- Attributes
Remarks
This operation will not block. The returned IAsyncOperationWithProgress (of HttpResponseMessage and HttpProgress) completes depending on the value of the completionOption parameter.
The HttpRequestMessage passed in the request parameter allows the SendRequestAsync method to set headers on the request message as well as on the HTTP content to be sent. In contrast, the PostAsync and PutAsync methods only allow setting a more limited set of HTTP content headers.
Below are the exceptions that this function throws.
E_ILLEGAL_METHOD_CALL
The request message was already sent by the HttpClient instance.
Exception handling
You must write code to handle exceptions when you call this method. Exceptions can result from parameter validation errors, name resolutions failures, and network errors. Exceptions from network errors (loss of connectivity, connection failures, and HTTP server failures, for example) can happen at any time. These errors result in exceptions being thrown. If not handled by your app, an exception can cause your entire app to be terminated by the runtime. For more information on how to handle exceptions, see Handling exceptions in network apps and How to: Map HRESULTs and Exceptions.
See also
Applies to
WinRT Build 26100 and other versions
Product | Versions |
---|---|
WinRT | Build 10240, Build 10586, Build 14383, Build 15063, Build 16299, Build 17134, Build 17763, Build 18362, Build 19041, Build 20348, Build 22000, Build 22621, Build 26100 |