WebClient.UploadStringAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Uploads the specified string to the specified resource. These methods do not block the calling thread.
Overloads
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)
- Source:
- WebClient.cs
- Source:
- WebClient.cs
- Source:
- WebClient.cs
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)
Parameters
- address
- Uri
The URI of the resource to receive the string. 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.
Exceptions
The URI formed by combining BaseAddress and address
is invalid.
-or-
There was no response from the server hosting the resource.
Remarks
Caution
WebRequest
, HttpWebRequest
, ServicePoint
, and WebClient
are obsolete, and you shouldn't use them for new development. Use HttpClient instead.
This method sends a string to a resource. The string is sent asynchronously using thread resources that are automatically allocated from the thread pool. Before uploading the string, this method converts it to a Byte array using the encoding specified in the Encoding property. 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. To send a string and block while waiting for the server's response, use one of the UploadString methods.
In .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.
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. If the QueryString property is not an empty string, it is appended to address
.
This method uses the STOR command to upload an FTP resource. For an HTTP resource, the POST method is used.
Note
This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in .NET Framework.
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by UploadString(Uri, String).
Applies to
UploadStringAsync(Uri, String, String)
- Source:
- WebClient.cs
- Source:
- WebClient.cs
- Source:
- WebClient.cs
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)
Parameters
- address
- Uri
The URI of the resource to receive the string. 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
The HTTP method used to send the file to the resource. If null, the default is POST for http and STOR for ftp.
- data
- String
The string to be uploaded.
Exceptions
The URI formed by combining BaseAddress and address
is invalid.
-or-
method
cannot be used to send content.
-or-
There was no response from the server hosting the resource.
Remarks
Caution
WebRequest
, HttpWebRequest
, ServicePoint
, and WebClient
are obsolete, and you shouldn't use them for new development. Use HttpClient instead.
This method sends a string to a resource. The string is sent asynchronously using thread resources that are automatically allocated from the thread pool. Before uploading the string, this method converts it to a Byte array using the encoding specified in the Encoding property. 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. To send a string and block while waiting for the server's response, use one of the UploadString methods.
In .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.
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. If the QueryString property is not an empty string, it is appended to address
.
Note
This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in .NET Framework.
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by UploadString(Uri, String, String).
Applies to
UploadStringAsync(Uri, String, String, Object)
- Source:
- WebClient.cs
- Source:
- WebClient.cs
- Source:
- WebClient.cs
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)
Parameters
- address
- Uri
The URI of the resource to receive the string. 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
The HTTP method used to send the file to the resource. 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.
Exceptions
The URI formed by combining BaseAddress and address
is invalid.
-or-
method
cannot be used to send content.
-or-
There was no response from the server hosting the resource.
Remarks
Caution
WebRequest
, HttpWebRequest
, ServicePoint
, and WebClient
are obsolete, and you shouldn't use them for new development. Use HttpClient instead.
This method sends a string to a resource. The string is sent asynchronously using thread resources that are automatically allocated from the thread pool. Before uploading the string, this method converts it to a Byte array using the encoding specified in the Encoding property. 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. To send a string and block while waiting for the server's response, use one of the UploadString methods.
In .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.
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. If the QueryString property is not an empty string, it is appended to address
.
Note
This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in .NET Framework.