HttpClient.SendRequestAsync HttpClient.SendRequestAsync HttpClient.SendRequestAsync HttpClient.SendRequestAsync HttpClient.SendRequestAsync Method

Definition

Overloads

SendRequestAsync(HttpRequestMessage) SendRequestAsync(HttpRequestMessage) SendRequestAsync(HttpRequestMessage) SendRequestAsync(HttpRequestMessage) 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) SendRequestAsync(HttpRequestMessage, HttpCompletionOption) SendRequestAsync(HttpRequestMessage, HttpCompletionOption) SendRequestAsync(HttpRequestMessage, HttpCompletionOption) 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.

SendRequestAsync(HttpRequestMessage) SendRequestAsync(HttpRequestMessage) SendRequestAsync(HttpRequestMessage) SendRequestAsync(HttpRequestMessage) 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.

public : IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress> SendRequestAsync(HttpRequestMessage request)
IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress> SendRequestAsync(HttpRequestMessage request) const;
public IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress> SendRequestAsync(HttpRequestMessage request)
Public Function SendRequestAsync(request As HttpRequestMessage) As IAsyncOperationWithProgress(Of HttpResponseMessageHttpProgress)
Windows.Web.Http.HttpClient.sendRequestAsync(request).done( /* Your success and error handlers */ );

Parameters

request
HttpRequestMessage HttpRequestMessage HttpRequestMessage

The HTTP request message to send.

Returns

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_INVALIDARG

The request parameter was a null reference (Nothing in Visual Basic).

E_ILLEGAL_METHOD_CALL

The request message was already sent by the HttpClient instance.

See also

SendRequestAsync(HttpRequestMessage, HttpCompletionOption) SendRequestAsync(HttpRequestMessage, HttpCompletionOption) SendRequestAsync(HttpRequestMessage, HttpCompletionOption) SendRequestAsync(HttpRequestMessage, HttpCompletionOption) 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.

public : IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress> SendRequestAsync(HttpRequestMessage request, HttpCompletionOption completionOption)
IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress> SendRequestAsync(HttpRequestMessage request, HttpCompletionOption completionOption) const;
public IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress> SendRequestAsync(HttpRequestMessage request, HttpCompletionOption completionOption)
Public Function SendRequestAsync(request As HttpRequestMessage, completionOption As HttpCompletionOption) As IAsyncOperationWithProgress(Of HttpResponseMessageHttpProgress)
Windows.Web.Http.HttpClient.sendRequestAsync(request, completionOption).done( /* Your success and error handlers */ );

Parameters

request
HttpRequestMessage HttpRequestMessage HttpRequestMessage

The HTTP request message to send.

completionOption
HttpCompletionOption HttpCompletionOption 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

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_INVALIDARG

The request parameter was a null reference (Nothing in Visual Basic).

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.

See also