WebClient.UploadValuesAsync Method

Definition

Uploads the specified name/value collection to the resource identified by the specified URI. These methods do not block the calling thread.

Overloads

UploadValuesAsync(Uri, NameValueCollection)

Uploads the data in the specified name/value collection to the resource identified by the specified URI. This method does not block the calling thread.

UploadValuesAsync(Uri, String, NameValueCollection)

Uploads the data in the specified name/value collection to the resource identified by the specified URI, using the specified method. This method does not block the calling thread.

UploadValuesAsync(Uri, String, NameValueCollection, Object)

Uploads the data in the specified name/value collection to the resource identified by the specified URI, using the specified method. This method does not block the calling thread, and allows the caller to pass an object to the method that is invoked when the operation completes.

UploadValuesAsync(Uri, NameValueCollection)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

Uploads the data in the specified name/value collection to the resource identified by the specified URI. This method does not block the calling thread.

public:
 void UploadValuesAsync(Uri ^ address, System::Collections::Specialized::NameValueCollection ^ data);
public void UploadValuesAsync (Uri address, System.Collections.Specialized.NameValueCollection data);
member this.UploadValuesAsync : Uri * System.Collections.Specialized.NameValueCollection -> unit
Public Sub UploadValuesAsync (address As Uri, data As NameValueCollection)

Parameters

address
Uri

The URI of the resource to receive the collection. This URI must identify a resource that can accept a request sent with the default method.

data
NameValueCollection

The NameValueCollection to send to the resource.

Exceptions

The address parameter is null.

-or-

The data parameter is null.

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 UploadValues(Uri, NameValueCollection).

Applies to

UploadValuesAsync(Uri, String, NameValueCollection)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

Uploads the data in the specified name/value collection to the resource identified by the specified URI, using the specified method. This method does not block the calling thread.

public:
 void UploadValuesAsync(Uri ^ address, System::String ^ method, System::Collections::Specialized::NameValueCollection ^ data);
public void UploadValuesAsync (Uri address, string? method, System.Collections.Specialized.NameValueCollection data);
public void UploadValuesAsync (Uri address, string method, System.Collections.Specialized.NameValueCollection data);
member this.UploadValuesAsync : Uri * string * System.Collections.Specialized.NameValueCollection -> unit
Public Sub UploadValuesAsync (address As Uri, method As String, data As NameValueCollection)

Parameters

address
Uri

The URI of the resource to receive the collection. This URI must identify a resource that can accept a request sent with the method method.

method
String

The method used to send the string to the resource. If null, the default is POST for http and STOR for ftp.

data
NameValueCollection

The NameValueCollection to send to the resource.

Exceptions

The address parameter is null.

-or-

The data parameter is null.

The URI formed by combining BaseAddress and address is invalid.

-or-

There was no response from the server hosting the resource.

-or-

method cannot be used to send content.

Remarks

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

This method sends the data contained in a NameValueCollection to the address resource. Use this method to send form data to a URI for processing. The data is sent using the form-urlencoded media type; the Content-Type header value must be set to "application/x-www-form-urlencoded". The header is set correctly by default. The UploadValuesAsync methods throw a WebException if you call this method with a different Content-Type header value set in the Headers collection.

If the method method is not understood by the server, the underlying protocol classes determine what occurs. Typically, a WebException is thrown with the Status property set to indicate the error.

The NameValueCollection is sent asynchronously using thread resources that are automatically allocated from the thread pool. To receive notification when the upload operation completes, add an event handler to the UploadValuesCompleted 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 UploadValues 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 empty, 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 UploadValues(Uri, String, NameValueCollection).

Applies to

UploadValuesAsync(Uri, String, NameValueCollection, Object)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

Uploads the data in the specified name/value collection to the resource identified by the specified URI, using the specified method. This method does not block the calling thread, and allows the caller to pass an object to the method that is invoked when the operation completes.

public:
 void UploadValuesAsync(Uri ^ address, System::String ^ method, System::Collections::Specialized::NameValueCollection ^ data, System::Object ^ userToken);
public void UploadValuesAsync (Uri address, string? method, System.Collections.Specialized.NameValueCollection data, object? userToken);
public void UploadValuesAsync (Uri address, string method, System.Collections.Specialized.NameValueCollection data, object userToken);
member this.UploadValuesAsync : Uri * string * System.Collections.Specialized.NameValueCollection * obj -> unit
Public Sub UploadValuesAsync (address As Uri, method As String, data As NameValueCollection, userToken As Object)

Parameters

address
Uri

The URI of the resource to receive the collection. This URI must identify a resource that can accept a request sent with the method method.

method
String

The HTTP method used to send the string to the resource. If null, the default is POST for http and STOR for ftp.

data
NameValueCollection

The NameValueCollection to send to the resource.

userToken
Object

A user-defined object that is passed to the method invoked when the asynchronous operation completes.

Exceptions

The address parameter is null.

-or-

The data parameter is null.

The URI formed by combining BaseAddress and address is invalid.

-or-

There was no response from the server hosting the resource.

-or-

method cannot be used to send content.

Remarks

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

This method sends the data contained in a NameValueCollection to the address resource. Use this method to send form data to a URI for processing. The data is sent using the form-urlencoded media type; the Content-Type header value must be set to "application/x-www-form-urlencoded". The header is set correctly by default. The UploadValuesAsync methods throw a WebException if you call this method with a different Content-Type header value set in the Headers collection.

If the method method is not understood by the server, the underlying protocol classes determine what occurs. Typically, a WebException is thrown with the Status property set to indicate the error.

The NameValueCollection is sent asynchronously using thread resources that are automatically allocated from the thread pool. To receive notification when the upload operation completes, add an event handler to the UploadValuesCompleted 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 UploadValues 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 empty, 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.

Applies to