Send a GET request to the specified URI and return the response body as a string in an asynchronous operation.
OverloadsThis operation doesn't block.
GetStringAsync(String)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
The URI the request is sent to.
ReturnsThe task object representing the asynchronous operation.
ExceptionsThe requestUri
is not an absolute URI and BaseAddress isn't set.
The request failed due to an issue getting a valid HTTP response, such as network connectivity failure, DNS failure, server certificate validation error, or invalid server response. On .NET 8 and later versions, the reason is indicated by HttpRequestError
-or-
The response status code was outside of the range of 200-299 (which indicate success according to the standard).
-or-
.NET Framework only: The request timed out.
.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.
RemarksThis operation doesn't block. The returned Task<TResult> object will complete after the whole response body is read. Internally, this operation uses HttpResponseMessage.EnsureSuccessStatusCode to ensure the response status code is in the success range (200-299) and throws an HttpRequestException if it is not. In some scenarios, you might need more control over which status codes are considered to be successful; for example, an API might be expected to always return 200 OK
. In such cases, we recommend to manually check if StatusCode matches the expected value.
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
The URI the request is sent to.
ReturnsThe task object representing the asynchronous operation.
ExceptionsThe requestUri
is not an absolute URI and BaseAddress isn't set.
The request failed due to an issue getting a valid HTTP response, such as network connectivity failure, DNS failure, server certificate validation error, or invalid server response. On .NET 8 and later versions, the reason is indicated by HttpRequestError
-or-
The response status code was outside of the range of 200-299 (which indicate success according to the standard).
-or-
.NET Framework only: The request timed out.
.NET Core and .NET 5 and later only: The request failed due to timeout.
RemarksThis operation doesn't block. The returned Task<TResult> object will complete after the whole response body is read. Internally, this operation uses HttpResponseMessage.EnsureSuccessStatusCode to ensure the response status code is in the success range (200-299) and throws an HttpRequestException if it is not. In some scenarios, you might need more control over which status codes are considered to be successful; for example, an API might be expected to always return 200 OK
. In such cases, we recommend to manually check if StatusCode matches the expected value.
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
The URI the request is sent to.
ReturnsThe task object representing the asynchronous operation.
ExceptionsThe request failed due to an issue getting a valid HTTP response, such as network connectivity failure, DNS failure, server certificate validation error, or invalid server response. On .NET 8 and later versions, the reason is indicated by HttpRequestError
-or-
The response status code was outside of the range of 200-299 (which indicate success according to the standard).
The provided request URI is not valid relative or absolute URI.
The cancellation token was canceled. This exception is stored into the returned task.
-or-
.NET Core and .NET 5 and later only: The request failed due to timeout.
RemarksThis operation doesn't block. The returned Task<TResult> object will complete after the whole response body is read. Internally, this operation uses HttpResponseMessage.EnsureSuccessStatusCode to ensure the response status code is in the success range (200-299) and throws an HttpRequestException if it is not. In some scenarios, you might need more control over which status codes are considered to be successful; for example, an API might be expected to always return 200 OK
. In such cases, we recommend to manually check if StatusCode matches the expected value.
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
The URI the request is sent to.
ReturnsThe task object representing the asynchronous operation.
ExceptionsThe request failed due to an issue getting a valid HTTP response, such as network connectivity failure, DNS failure, server certificate validation error, or invalid server response. On .NET 8 and later versions, the reason is indicated by HttpRequestError
-or-
The response status code was outside of the range of 200-299 (which indicate success according to the standard).
The cancellation token was canceled. This exception is stored into the returned task.
-or-
.NET Core and .NET 5 and later only: The request failed due to timeout.
RemarksThis operation doesn't block. The returned Task<TResult> object will complete after the whole response body is read. Internally, this operation uses HttpResponseMessage.EnsureSuccessStatusCode to ensure the response status code is in the success range (200-299) and throws an HttpRequestException if it is not. In some scenarios, you might need more control over which status codes are considered to be successful; for example, an API might be expected to always return 200 OK
. In such cases, we recommend to manually check if StatusCode matches the expected value.
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. In this articleWas this page helpful?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4