WebClient.UploadStringTaskAsync 方法

定义

使用任务对象将指定字符串上载到指定资源以作为异步操作。Uploads the specified string to the specified resource as an asynchronous operation using a task object. 这些方法不阻止调用线程。These methods do not block the calling thread.

重载

UploadStringTaskAsync(Uri, String, String)

使用任务对象将指定字符串上载到指定资源以作为异步操作。Uploads the specified string to the specified resource as an asynchronous operation using a task object.

UploadStringTaskAsync(String, String, String)

使用任务对象将指定字符串上载到指定资源以作为异步操作。Uploads the specified string to the specified resource as an asynchronous operation using a task object.

UploadStringTaskAsync(String, String)

使用任务对象将指定字符串上载到指定资源以作为异步操作。Uploads the specified string to the specified resource as an asynchronous operation using a task object.

UploadStringTaskAsync(Uri, String)

使用任务对象将指定字符串上载到指定资源以作为异步操作。Uploads the specified string to the specified resource as an asynchronous operation using a task object.

UploadStringTaskAsync(Uri, String, String)

使用任务对象将指定字符串上载到指定资源以作为异步操作。Uploads the specified string to the specified resource as an asynchronous operation using a task object.

public:
 System::Threading::Tasks::Task<System::String ^> ^ UploadStringTaskAsync(Uri ^ address, System::String ^ method, System::String ^ data);
public System.Threading.Tasks.Task<string> UploadStringTaskAsync (Uri address, string? method, string data);
public System.Threading.Tasks.Task<string> UploadStringTaskAsync (Uri address, string method, string data);
[System.Runtime.InteropServices.ComVisible(false)]
public System.Threading.Tasks.Task<string> UploadStringTaskAsync (Uri address, string method, string data);
member this.UploadStringTaskAsync : Uri * string * string -> System.Threading.Tasks.Task<string>
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.UploadStringTaskAsync : Uri * string * string -> System.Threading.Tasks.Task<string>
Public Function UploadStringTaskAsync (address As Uri, method As String, data As String) As Task(Of String)

参数

address
Uri

要接收字符串的资源的 URI。The URI of the resource to receive the string. 对于 HTTP 资源,此 URI 必须标识可以接受用 POST 方法发送的请求的资源,如脚本或 ASP 页。For HTTP resources, this URI must identify a resource that can accept a request sent with the POST method, such as a script or ASP page.

method
String

用于将文件发送到资源的 HTTP 方法。The HTTP method used to send the file to the resource. 如果为 null,则对于 http 默认值为 POST,对于 ftp 默认值为 STOR。If null, the default is POST for http and STOR for ftp.

data
String

要上载的字符串。The string to be uploaded.

返回

Task<String>

表示异步操作的任务对象。The task object representing the asynchronous operation. 任务对象上的 Result 属性将返回包含服务器发送的响应的 StringThe Result property on the task object returns a String containing the response sent by the server.

属性

例外

address 参数为 nullThe address parameter is null.

- 或 --or-

data 参数为 nullThe data parameter is null.

通过组合 BaseAddressaddress 所构成的 URI 无效。The URI formed by combining BaseAddress and address is invalid.

- 或 --or-

method 不能用来发送内容。method cannot be used to send content.

- 或 --or-

承载资源的服务器没有响应。There was no response from the server hosting the resource.

注解

此操作不会阻止。This operation will not block. Task<TResult>将字符串上载到资源后,返回的对象将完成。The returned Task<TResult> object will complete after the string has been uploaded to the resource. 该字符串使用自动从线程池分配的线程资源进行异步发送。The string is sent asynchronously using thread resources that are automatically allocated from the thread pool.

在 .NET Framework 和 .NET Core 1.0 中,可以通过调用方法取消尚未完成的异步操作 CancelAsyncIn .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.

在上传字符串之前,此方法 Byte 使用属性中指定的编码将其转换为 Encoding 数组。Before uploading the string, this method converts it to a Byte array using the encoding specified in the Encoding property. 传输字符串时,此方法将会阻止。This method blocks while the string is transmitted.

如果该 BaseAddress 属性不是空字符串 ( "" ) 并且不 address 包含绝对 uri, address 则必须是与组合的相对 uri, BaseAddress 才能形成所请求数据的绝对 uri。If the BaseAddress property is not an empty string ("") and address does not contain an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. 如果该 QueryString 属性不是空字符串,则将其追加到 addressIf the QueryString property is not an empty string, it is appended to address.

备注

当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅 .NET Framework 中的网络跟踪For more information, see Network Tracing in .NET Framework.

适用于

UploadStringTaskAsync(String, String, String)

使用任务对象将指定字符串上载到指定资源以作为异步操作。Uploads the specified string to the specified resource as an asynchronous operation using a task object.

public:
 System::Threading::Tasks::Task<System::String ^> ^ UploadStringTaskAsync(System::String ^ address, System::String ^ method, System::String ^ data);
public System.Threading.Tasks.Task<string> UploadStringTaskAsync (string address, string? method, string data);
public System.Threading.Tasks.Task<string> UploadStringTaskAsync (string address, string method, string data);
[System.Runtime.InteropServices.ComVisible(false)]
public System.Threading.Tasks.Task<string> UploadStringTaskAsync (string address, string method, string data);
member this.UploadStringTaskAsync : string * string * string -> System.Threading.Tasks.Task<string>
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.UploadStringTaskAsync : string * string * string -> System.Threading.Tasks.Task<string>
Public Function UploadStringTaskAsync (address As String, method As String, data As String) As Task(Of String)

参数

address
String

要接收字符串的资源的 URI。The URI of the resource to receive the string. 对于 HTTP 资源,此 URI 必须标识可以接受用 POST 方法发送的请求的资源,如脚本或 ASP 页。For HTTP resources, this URI must identify a resource that can accept a request sent with the POST method, such as a script or ASP page.

method
String

用于将文件发送到资源的 HTTP 方法。The HTTP method used to send the file to the resource. 如果为 null,则对于 http 默认值为 POST,对于 ftp 默认值为 STOR。If null, the default is POST for http and STOR for ftp.

data
String

要上载的字符串。The string to be uploaded.

返回

Task<String>

表示异步操作的任务对象。The task object representing the asynchronous operation. 任务对象上的 Result 属性将返回包含服务器发送的响应的 StringThe Result property on the task object returns a String containing the response sent by the server.

属性

例外

address 参数为 nullThe address parameter is null.

- 或 --or-

data 参数为 nullThe data parameter is null.

通过组合 BaseAddressaddress 所构成的 URI 无效。The URI formed by combining BaseAddress and address is invalid.

- 或 --or-

method 不能用来发送内容。method cannot be used to send content.

- 或 --or-

承载资源的服务器没有响应。There was no response from the server hosting the resource.

注解

此操作不会阻止。This operation will not block. Task<TResult>将字符串上载到资源后,返回的对象将完成。The returned Task<TResult> object will complete after the string has been uploaded to the resource. 该字符串使用自动从线程池分配的线程资源进行异步发送。The string is sent asynchronously using thread resources that are automatically allocated from the thread pool.

在 .NET Framework 和 .NET Core 1.0 中,可以通过调用方法取消尚未完成的异步操作 CancelAsyncIn .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.

在上传字符串之前,此方法 Byte 使用属性中指定的编码将其转换为 Encoding 数组。Before uploading the string, this method converts it to a Byte array using the encoding specified in the Encoding property. 传输字符串时,此方法将会阻止。This method blocks while the string is transmitted.

如果该 BaseAddress 属性不是空字符串 ( "" ) 并且不 address 包含绝对 uri, address 则必须是与组合的相对 uri, BaseAddress 才能形成所请求数据的绝对 uri。If the BaseAddress property is not an empty string ("") and address does not contain an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. 如果该 QueryString 属性不是空字符串,则将其追加到 addressIf the QueryString property is not an empty string, it is appended to address.

备注

当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅 .NET Framework 中的网络跟踪For more information, see Network Tracing in .NET Framework.

适用于

UploadStringTaskAsync(String, String)

使用任务对象将指定字符串上载到指定资源以作为异步操作。Uploads the specified string to the specified resource as an asynchronous operation using a task object.

public:
 System::Threading::Tasks::Task<System::String ^> ^ UploadStringTaskAsync(System::String ^ address, System::String ^ data);
public System.Threading.Tasks.Task<string> UploadStringTaskAsync (string address, string data);
[System.Runtime.InteropServices.ComVisible(false)]
public System.Threading.Tasks.Task<string> UploadStringTaskAsync (string address, string data);
member this.UploadStringTaskAsync : string * string -> System.Threading.Tasks.Task<string>
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.UploadStringTaskAsync : string * string -> System.Threading.Tasks.Task<string>
Public Function UploadStringTaskAsync (address As String, data As String) As Task(Of String)

参数

address
String

要接收字符串的资源的 URI。The URI of the resource to receive the string. 对于 HTTP 资源,此 URI 必须标识可以接受用 POST 方法发送的请求的资源,如脚本或 ASP 页。For HTTP resources, this URI must identify a resource that can accept a request sent with the POST method, such as a script or ASP page.

data
String

要上载的字符串。The string to be uploaded.

返回

Task<String>

表示异步操作的任务对象。The task object representing the asynchronous operation. 任务对象上的 Result 属性将返回包含服务器发送的响应的 StringThe Result property on the task object returns a String containing the response sent by the server.

属性

例外

address 参数为 nullThe address parameter is null.

- 或 --or-

data 参数为 nullThe data parameter is null.

通过组合 BaseAddressaddress 所构成的 URI 无效。The URI formed by combining BaseAddress and address is invalid.

- 或 --or-

承载资源的服务器没有响应。There was no response from the server hosting the resource.

注解

此操作不会阻止。This operation will not block. Task<TResult>将字符串上载到资源后,返回的对象将完成。The returned Task<TResult> object will complete after the string has been uploaded to the resource. 该字符串使用自动从线程池分配的线程资源进行异步发送。The string is sent asynchronously using thread resources that are automatically allocated from the thread pool.

在 .NET Framework 和 .NET Core 1.0 中,可以通过调用方法取消尚未完成的异步操作 CancelAsyncIn .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.

在上传字符串之前,此方法 Byte 使用属性中指定的编码将其转换为 Encoding 数组。Before uploading the string, this method converts it to a Byte array using the encoding specified in the Encoding property. 传输字符串时,此方法将会阻止。This method blocks while the string is transmitted.

如果该 BaseAddress 属性不是空字符串 ( "" ) 并且不 address 包含绝对 uri, address 则必须是与组合的相对 uri, BaseAddress 才能形成所请求数据的绝对 uri。If the BaseAddress property is not an empty string ("") and address does not contain an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. 如果该 QueryString 属性不是空字符串,则将其追加到 addressIf the QueryString property is not an empty string, it is appended to address.

备注

当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅 .NET Framework 中的网络跟踪For more information, see Network Tracing in .NET Framework.

适用于

UploadStringTaskAsync(Uri, String)

使用任务对象将指定字符串上载到指定资源以作为异步操作。Uploads the specified string to the specified resource as an asynchronous operation using a task object.

public:
 System::Threading::Tasks::Task<System::String ^> ^ UploadStringTaskAsync(Uri ^ address, System::String ^ data);
public System.Threading.Tasks.Task<string> UploadStringTaskAsync (Uri address, string data);
[System.Runtime.InteropServices.ComVisible(false)]
public System.Threading.Tasks.Task<string> UploadStringTaskAsync (Uri address, string data);
member this.UploadStringTaskAsync : Uri * string -> System.Threading.Tasks.Task<string>
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.UploadStringTaskAsync : Uri * string -> System.Threading.Tasks.Task<string>
Public Function UploadStringTaskAsync (address As Uri, data As String) As Task(Of String)

参数

address
Uri

要接收字符串的资源的 URI。The URI of the resource to receive the string. 对于 HTTP 资源,此 URI 必须标识可以接受用 POST 方法发送的请求的资源,如脚本或 ASP 页。For HTTP resources, this URI must identify a resource that can accept a request sent with the POST method, such as a script or ASP page.

data
String

要上载的字符串。The string to be uploaded.

返回

Task<String>

表示异步操作的任务对象。The task object representing the asynchronous operation. 任务对象上的 Result 属性将返回包含服务器发送的响应的 StringThe Result property on the task object returns a String containing the response sent by the server.

属性

例外

address 参数为 nullThe address parameter is null.

- 或 --or-

data 参数为 nullThe data parameter is null.

通过组合 BaseAddressaddress 所构成的 URI 无效。The URI formed by combining BaseAddress and address is invalid.

- 或 --or-

承载资源的服务器没有响应。There was no response from the server hosting the resource.

注解

此操作不会阻止。This operation will not block. Task<TResult>将字符串上载到资源后,返回的对象将完成。The returned Task<TResult> object will complete after the string has been uploaded to the resource. 该字符串使用自动从线程池分配的线程资源进行异步发送。The string is sent asynchronously using thread resources that are automatically allocated from the thread pool.

在 .NET Framework 和 .NET Core 1.0 中,可以通过调用方法取消尚未完成的异步操作 CancelAsyncIn .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.

在上传字符串之前,此方法 Byte 使用属性中指定的编码将其转换为 Encoding 数组。Before uploading the string, this method converts it to a Byte array using the encoding specified in the Encoding property. 传输字符串时,此方法将会阻止。This method blocks while the string is transmitted.

如果该 BaseAddress 属性不是空字符串 ( "" ) 并且不 address 包含绝对 uri, address 则必须是与组合的相对 uri, BaseAddress 才能形成所请求数据的绝对 uri。If the BaseAddress property is not an empty string ("") and address does not contain an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. 如果该 QueryString 属性不是空字符串,则将其追加到 addressIf the QueryString property is not an empty string, it is appended to address.

备注

当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅 .NET Framework 中的网络跟踪For more information, see Network Tracing in .NET Framework.

适用于