Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

HttpClient.SendRequestAsync(HttpRequestMessage, HttpCompletionOption) | sendRequestAsync(HttpRequestMessage, HttpCompletionOption) method

Applies to Windows and Windows Phone

Send an HTTP request with an HTTP completion option as an asynchronous operation.

Syntax


httpClient.sendRequestAsync(request, completionOption).done( /* Your success and error handlers */ );

Parameters

request

Type: HttpRequestMessage

The HTTP request message to send.

completionOption

Type: 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.

Return value

Type: IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress>

The object representing the asynchronous operation.

Exceptions

A number of exceptions can occur when calling this method. Only a few of the possible errors that can cause exceptions are listed.

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.

An app can use the HRESULT from the exception to learn more detailed information on the error that caused the exception.

For more information on possible exceptions and how to handle exceptions, see Handling exceptions in network apps.

ExceptionCondition
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.

Remarks

This operation will not block. The returned IAsyncOperationWithProgress(HttpResponseMessage, HttpProgress) object will complete 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.

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.

Requirements

Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Web.Http
Windows::Web::Http [C++]

Metadata

Windows.winmd

See also

HttpClient
HttpRequestMessage
PostAsync
SendRequestAsync(HttpRequestMessage)

 

 

Show:
© 2014 Microsoft. All rights reserved.