Muokkaa

Jaa


HttpClient.GetStringAsync Method

Definition

Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation.

Overloads

GetStringAsync(String)

Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation.

GetStringAsync(Uri)

Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation.

GetStringAsync(String, CancellationToken)

Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation.

GetStringAsync(Uri, CancellationToken)

Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation.

Remarks

This operation will not block.

GetStringAsync(String)

Source:
HttpClient.cs
Source:
HttpClient.cs
Source:
HttpClient.cs

Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::String ^> ^ GetStringAsync(System::String ^ requestUri);
public System.Threading.Tasks.Task<string> GetStringAsync (string requestUri);
public System.Threading.Tasks.Task<string> GetStringAsync (string? requestUri);
member this.GetStringAsync : string -> System.Threading.Tasks.Task<string>
Public Function GetStringAsync (requestUri As String) As Task(Of String)

Parameters

requestUri
String

The Uri the request is sent to.

Returns

The task object representing the asynchronous operation.

Exceptions

The requestUri must be an absolute URI or BaseAddress must be set.

The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation (or timeout for .NET Framework only).

.NET Core and .NET 5 and later only: The request failed due to timeout.

The provided request URI is not valid relative or absolute URI.

Remarks

This operation will not block. The returned Task<TResult> object will complete after the whole response body is read.

Note

In case of a timeout:

Applies to

GetStringAsync(Uri)

Source:
HttpClient.cs
Source:
HttpClient.cs
Source:
HttpClient.cs

Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::String ^> ^ GetStringAsync(Uri ^ requestUri);
public System.Threading.Tasks.Task<string> GetStringAsync (Uri requestUri);
public System.Threading.Tasks.Task<string> GetStringAsync (Uri? requestUri);
member this.GetStringAsync : Uri -> System.Threading.Tasks.Task<string>
Public Function GetStringAsync (requestUri As Uri) As Task(Of String)

Parameters

requestUri
Uri

The Uri the request is sent to.

Returns

The task object representing the asynchronous operation.

Exceptions

The requestUri must be an absolute URI or BaseAddress must be set.

The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation (or timeout for .NET Framework only).

.NET Core and .NET 5 and later only: The request failed due to timeout.

Remarks

This operation will not block. The returned Task<TResult> object will complete after the whole response body is read.

Note

In case of a timeout:

Applies to

GetStringAsync(String, CancellationToken)

Source:
HttpClient.cs
Source:
HttpClient.cs
Source:
HttpClient.cs

Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation.

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

Parameters

requestUri
String

The Uri the request is sent to.

cancellationToken
CancellationToken

The cancellation token to cancel the operation.

Returns

The task object representing the asynchronous operation.

Exceptions

The requestUri is null.

The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation (or timeout for .NET Framework only).

.NET Core and .NET 5 and later only: The request failed due to timeout.

The provided request URI is not valid relative or absolute URI.

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

This operation will not block. The returned Task<TResult> object will complete after the whole response body is read.

Note

In case of a timeout:

Applies to

GetStringAsync(Uri, CancellationToken)

Source:
HttpClient.cs
Source:
HttpClient.cs
Source:
HttpClient.cs

Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::String ^> ^ GetStringAsync(Uri ^ requestUri, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<string> GetStringAsync (Uri? requestUri, System.Threading.CancellationToken cancellationToken);
member this.GetStringAsync : Uri * System.Threading.CancellationToken -> System.Threading.Tasks.Task<string>
Public Function GetStringAsync (requestUri As Uri, cancellationToken As CancellationToken) As Task(Of String)

Parameters

requestUri
Uri

The Uri the request is sent to.

cancellationToken
CancellationToken

The cancellation token to cancel the operation.

Returns

The task object representing the asynchronous operation.

Exceptions

The requestUri is null.

The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation (or timeout for .NET Framework only).

.NET Core and .NET 5 and later only: The request failed due to timeout.

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

This operation will not block. The returned Task<TResult> object will complete after the whole response body is read.

Note

In case of a timeout:

Applies to