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.

注意

如果是 timeout: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.

注意

如果是 timeout: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.

注意

如果是 timeout: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.

注意

如果是 timeout:In case of a timeout:

適用於