HttpClient.GetStringAsync 方法

定义

将 GET 请求发送到指定 URI 并在异步操作中以字符串的形式返回响应正文。Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation.

重载

GetStringAsync(String)

将 GET 请求发送到指定 URI 并在异步操作中以字符串的形式返回响应正文。Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation.

GetStringAsync(Uri)

将 GET 请求发送到指定 URI 并在异步操作中以字符串的形式返回响应正文。Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation.

GetStringAsync(String, CancellationToken)

将 GET 请求发送到指定 URI 并在异步操作中以字符串的形式返回响应正文。Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation.

GetStringAsync(Uri, CancellationToken)

将 GET 请求发送到指定 URI 并在异步操作中以字符串的形式返回响应正文。Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation.

注解

此操作不会阻止。This operation will not block.

GetStringAsync(String)

将 GET 请求发送到指定 URI 并在异步操作中以字符串的形式返回响应正文。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)

参数

requestUri
String

请求发送到的 URI。The Uri the request is sent to.

返回

Task<String>

表示异步操作的任务对象。The task object representing the asynchronous operation.

例外

requestUri 必须为绝对 URI 或必须设置 BaseAddressThe requestUri must be an absolute URI or BaseAddress must be set.

由于基础问题(如网络连接性、DNS 失败、服务器证书验证或仅 .NET Framework 超时),请求失败。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 和 .NET 5.0 及更高版本:请求因超时而失败。.NET Core and .NET 5.0 and later only: The request failed due to timeout.

注解

此操作不会阻止。This operation will not block. Task<TResult> 读取整个响应正文后,返回的对象将完成。The returned Task<TResult> object will complete after the whole response body is read.

备注

如果超时,则:In case of a timeout:

适用于

GetStringAsync(Uri)

将 GET 请求发送到指定 URI 并在异步操作中以字符串的形式返回响应正文。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)

参数

requestUri
Uri

请求发送到的 URI。The Uri the request is sent to.

返回

Task<String>

表示异步操作的任务对象。The task object representing the asynchronous operation.

例外

requestUri 必须为绝对 URI 或必须设置 BaseAddressThe requestUri must be an absolute URI or BaseAddress must be set.

由于基础问题(如网络连接性、DNS 失败、服务器证书验证或仅 .NET Framework 超时),请求失败。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 和 .NET 5.0 及更高版本:请求因超时而失败。.NET Core and .NET 5.0 and later only: The request failed due to timeout.

注解

此操作不会阻止。This operation will not block. Task<TResult> 读取整个响应正文后,返回的对象将完成。The returned Task<TResult> object will complete after the whole response body is read.

备注

如果超时,则:In case of a timeout:

适用于

GetStringAsync(String, CancellationToken)

将 GET 请求发送到指定 URI 并在异步操作中以字符串的形式返回响应正文。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)

参数

requestUri
String

请求发送到的 URI。The Uri the request is sent to.

cancellationToken
CancellationToken

用于取消操作的取消令牌。The cancellation token to cancel the operation.

返回

Task<String>

表示异步操作的任务对象。The task object representing the asynchronous operation.

例外

requestUrinullThe requestUri is null.

由于基础问题(如网络连接性、DNS 失败、服务器证书验证或仅 .NET Framework 超时),请求失败。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 和 .NET 5.0 及更高版本:请求因超时而失败。.NET Core and .NET 5.0 and later only: The request failed due to timeout.

注解

此操作不会阻止。This operation will not block. Task<TResult> 读取整个响应正文后,返回的对象将完成。The returned Task<TResult> object will complete after the whole response body is read.

备注

如果超时,则:In case of a timeout:

适用于

GetStringAsync(Uri, CancellationToken)

将 GET 请求发送到指定 URI 并在异步操作中以字符串的形式返回响应正文。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)

参数

requestUri
Uri

请求发送到的 URI。The Uri the request is sent to.

cancellationToken
CancellationToken

用于取消操作的取消令牌。The cancellation token to cancel the operation.

返回

Task<String>

表示异步操作的任务对象。The task object representing the asynchronous operation.

例外

requestUrinullThe requestUri is null.

由于基础问题(如网络连接性、DNS 失败、服务器证书验证或仅 .NET Framework 超时),请求失败。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 和 .NET 5.0 及更高版本:请求因超时而失败。.NET Core and .NET 5.0 and later only: The request failed due to timeout.

注解

此操作不会阻止。This operation will not block. Task<TResult> 读取整个响应正文后,返回的对象将完成。The returned Task<TResult> object will complete after the whole response body is read.

备注

如果超时,则:In case of a timeout:

适用于