Megosztás a következőn keresztül:


HttpClient.GetAsync Method

Definition

Overloads

GetAsync(Uri)

Send a GET request to the specified Uri as an asynchronous operation. For programming guidance for the HttpClient class, and code examples, see the HttpClient conceptual topic.

GetAsync(Uri, HttpCompletionOption)

Send a GET request to the specified Uri with an HTTP completion option as an asynchronous operation. For programming guidance for the HttpClient class, and code examples, see the HttpClient conceptual topic.

GetAsync(Uri)

Send a GET request to the specified Uri as an asynchronous operation. For programming guidance for the HttpClient class, and code examples, see the HttpClient conceptual topic.

public:
 virtual IAsyncOperationWithProgress<HttpResponseMessage ^, HttpProgress> ^ GetAsync(Uri ^ uri) = GetAsync;
/// [Windows.Foundation.Metadata.Overload("GetAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress> GetAsync(Uri const& uri);
[Windows.Foundation.Metadata.Overload("GetAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperationWithProgress<HttpResponseMessage,HttpProgress> GetAsync(System.Uri uri);
function getAsync(uri)
Public Function GetAsync (uri As Uri) As IAsyncOperationWithProgress(Of HttpResponseMessage, HttpProgress)

Parameters

uri
Uri Uri

The Uri to which the request is to be sent.

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.

For sample code in C#/VB/C++ and XAML that shows how to use HttpClient and GetAsync(Uri) to connect to an HTTP server and send a GET request, see HttpClient.

For sample code in JavaScript and HTML that shows how to use HttpClient and GetAsync(Uri) to connect to an HTTP server and send a GET request, see Connecting to an HTTP server using Windows.Web.Http.

Below are the exceptions that this function throws.

COMException

Thrown when a feature-specific HRESULT is returned from a method call.

This is the most common exception that is thrown by networking methods. An app should use the HRESULT from the exception to determine the cause of the error.

AccessDeniedException

Thrown when access is denied to a resource or feature. This exception occurs when an app doesn't have the required network capabilities set in the app manifest for the network operation requested.

InvalidArgumentException

Thrown when one of the arguments that are provided to a method is not valid.

If user-supplied input caused this exception, an app could inform the user and request new input.

ObjectDisposedException

Thrown when an operation is performed on a disposed object.

OutOfMemoryException

Thrown when insufficient memory is available to complete the operation.

See also

Applies to

GetAsync(Uri, HttpCompletionOption)

Send a GET request to the specified Uri 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> ^ GetAsync(Uri ^ uri, HttpCompletionOption completionOption) = GetAsync;
/// [Windows.Foundation.Metadata.Overload("GetWithOptionAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress> GetAsync(Uri const& uri, HttpCompletionOption const& completionOption);
[Windows.Foundation.Metadata.Overload("GetWithOptionAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperationWithProgress<HttpResponseMessage,HttpProgress> GetAsync(System.Uri uri, HttpCompletionOption completionOption);
function getAsync(uri, completionOption)
Public Function GetAsync (uri As Uri, completionOption As HttpCompletionOption) As IAsyncOperationWithProgress(Of HttpResponseMessage, HttpProgress)

Parameters

uri
Uri Uri

The Uri the request is sent to.

completionOption
HttpCompletionOption

An HTTP completion option value that indicates when the operation should be considered completed.

Returns

The object representing the asynchronous operation.

Attributes

Remarks

This operation will not block. The returned IAsyncOperationWithProgress (of HttpResponseMessage and HttpProgress) completes based on the completionOption parameter after part or all of the response (including content) is read.

Below are the exceptions that this content throws.

COMException

Thrown when a feature-specific HRESULT is returned from a method call.

This is the most common exception that is thrown by networking methods. An app should use the HRESULT from the exception to determine the cause of the error.

AccessDeniedException

Thrown when access is denied to a resource or feature. This exception occurs when an app doesn't have the required network capabilities set in the app manifest for the network operation requested.

InvalidArgumentException

Thrown when one of the arguments that are provided to a method is not valid.

If user-supplied input caused this exception, an app could inform the user and request new input.

ObjectDisposedException

Thrown when an operation is performed on a disposed object.

OutOfMemoryException

Thrown when insufficient memory is available to complete the operation.

See also

Applies to