WebClient.UploadStringAsync 方法
定义
将指定的字符串上载到指定的资源。Uploads the specified string to the specified resource. 这些方法不阻止调用线程。These methods do not block the calling thread.
重载
| UploadStringAsync(Uri, String) |
将指定的字符串上载到指定的资源。Uploads the specified string to the specified resource. 此方法不会阻止调用线程。This method does not block the calling thread. |
| UploadStringAsync(Uri, String, String) |
将指定的字符串上载到指定的资源。Uploads the specified string to the specified resource. 此方法不会阻止调用线程。This method does not block the calling thread. |
| UploadStringAsync(Uri, String, String, Object) |
将指定的字符串上载到指定的资源。Uploads the specified string to the specified resource. 此方法不会阻止调用线程。This method does not block the calling thread. |
UploadStringAsync(Uri, String)
将指定的字符串上载到指定的资源。Uploads the specified string to the specified resource. 此方法不会阻止调用线程。This method does not block the calling thread.
public:
void UploadStringAsync(Uri ^ address, System::String ^ data);
public void UploadStringAsync (Uri address, string data);
member this.UploadStringAsync : Uri * string -> unit
Public Sub UploadStringAsync (address As Uri, data As 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.
例外
address 参数为 null。The address parameter is null.
- 或 --or-
data 参数为 null。The data parameter is null.
通过组合 BaseAddress 和 address 所构成的 URI 无效。The URI formed by combining BaseAddress and address is invalid.
- 或 --or-
承载资源的服务器没有响应。There was no response from the server hosting the resource.
注解
此方法将字符串发送到资源。This method sends a string to a resource. 该字符串使用自动从线程池分配的线程资源进行异步发送。The string is sent asynchronously using thread resources that are automatically allocated from the thread pool. 在上传字符串之前,此方法 Byte 使用属性中指定的编码将其转换为 Encoding 数组。Before uploading the string, this method converts it to a Byte array using the encoding specified in the Encoding property. 若要在字符串上传完成时接收通知,可以向事件添加事件处理程序 UploadStringCompleted 。To receive notification when the string upload completes, you can add an event handler to the UploadStringCompleted event.
在发送字符串时,此方法不会阻止调用线程。This method does not block the calling thread while the string is being sent. 若要在等待服务器响应的同时发送字符串和块,请使用其中一种 UploadString 方法。To send a string and block while waiting for the server's response, use one of the UploadString methods.
在 .NET Framework 和 .NET Core 1.0 中,可以通过调用方法取消尚未完成的异步操作 CancelAsync 。In .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.
如果该 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 属性不是空字符串,则将其追加到 address 。If the QueryString property is not an empty string, it is appended to address.
此方法使用 STOR 命令上传 FTP 资源。This method uses the STOR command to upload an FTP resource. 对于 HTTP 资源,使用 POST 方法。For an HTTP resource, the POST method is used.
备注
当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅 .NET Framework 中的网络跟踪。For more information, see Network Tracing in .NET Framework.
适用于
UploadStringAsync(Uri, String, String)
将指定的字符串上载到指定的资源。Uploads the specified string to the specified resource. 此方法不会阻止调用线程。This method does not block the calling thread.
public:
void UploadStringAsync(Uri ^ address, System::String ^ method, System::String ^ data);
public void UploadStringAsync (Uri address, string? method, string data);
public void UploadStringAsync (Uri address, string method, string data);
member this.UploadStringAsync : Uri * string * string -> unit
Public Sub UploadStringAsync (address As Uri, method As String, data As 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.
例外
address 参数为 null。The address parameter is null.
- 或 --or-
data 参数为 null。The data parameter is null.
通过组合 BaseAddress 和 address 所构成的 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 method sends a string to a resource. 该字符串使用自动从线程池分配的线程资源进行异步发送。The string is sent asynchronously using thread resources that are automatically allocated from the thread pool. 在上传字符串之前,此方法 Byte 使用属性中指定的编码将其转换为 Encoding 数组。Before uploading the string, this method converts it to a Byte array using the encoding specified in the Encoding property. 若要在字符串上传完成时接收通知,可以向事件添加事件处理程序 UploadStringCompleted 。To receive notification when the string upload completes, you can add an event handler to the UploadStringCompleted event.
在发送字符串时,此方法不会阻止调用线程。This method does not block the calling thread while the string is being sent. 若要在等待服务器响应的同时发送字符串和块,请使用其中一种 UploadString 方法。To send a string and block while waiting for the server's response, use one of the UploadString methods.
在 .NET Framework 和 .NET Core 1.0 中,可以通过调用方法取消尚未完成的异步操作 CancelAsync 。In .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.
如果该 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 属性不是空字符串,则将其追加到 address 。If 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.
适用于
UploadStringAsync(Uri, String, String, Object)
将指定的字符串上载到指定的资源。Uploads the specified string to the specified resource. 此方法不会阻止调用线程。This method does not block the calling thread.
public:
void UploadStringAsync(Uri ^ address, System::String ^ method, System::String ^ data, System::Object ^ userToken);
public void UploadStringAsync (Uri address, string? method, string data, object? userToken);
public void UploadStringAsync (Uri address, string method, string data, object userToken);
member this.UploadStringAsync : Uri * string * string * obj -> unit
Public Sub UploadStringAsync (address As Uri, method As String, data As String, userToken As Object)
参数
- 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.
- userToken
- Object
一个用户定义对象,此对象将传递给完成异步操作后所调用的方法。A user-defined object that is passed to the method invoked when the asynchronous operation completes.
例外
address 参数为 null。The address parameter is null.
- 或 --or-
data 参数为 null。The data parameter is null.
通过组合 BaseAddress 和 address 所构成的 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 method sends a string to a resource. 该字符串使用自动从线程池分配的线程资源进行异步发送。The string is sent asynchronously using thread resources that are automatically allocated from the thread pool. 在上传字符串之前,此方法 Byte 使用属性中指定的编码将其转换为 Encoding 数组。Before uploading the string, this method converts it to a Byte array using the encoding specified in the Encoding property. 若要在字符串上传完成时接收通知,可以向事件添加事件处理程序 UploadStringCompleted 。To receive notification when the string upload completes, you can add an event handler to the UploadStringCompleted event.
在发送字符串时,此方法不会阻止调用线程。This method does not block the calling thread while the string is being sent. 若要在等待服务器响应的同时发送字符串和块,请使用其中一种 UploadString 方法。To send a string and block while waiting for the server's response, use one of the UploadString methods.
在 .NET Framework 和 .NET Core 1.0 中,可以通过调用方法取消尚未完成的异步操作 CancelAsync 。In .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.
如果该 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 属性不是空字符串,则将其追加到 address 。If 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.