See Also: WebClient Members
The System.Net.WebClient class provides common methods for sending data to or receiving data from any local, intranet, or Internet resource identified by a URI.
The System.Net.WebClient class uses the System.Net.WebRequest class to provide access to resources. System.Net.WebClient instances can access data with any System.Net.WebRequest descendant registered with the WebRequest.RegisterPrefix(string, IWebRequestCreate) method.
By default, the .NET Framework supports URIs that begin with http:, https:, ftp:, and file: scheme identifiers.
The following table describes System.Net.WebClient methods for uploading data to a resource.
WebClient.OpenWrite(string) |
Retrieves a System.IO.Stream used to send data to the resource. |
WebClient.OpenWriteAsync(Uri) |
Retrieves a System.IO.Stream used to send data to the resource, without blocking the calling thread. |
WebClient.UploadData(string, Byte[]) |
Sends a byte array to the resource and returns a byte array containing any response. |
WebClient.UploadDataAsync(Uri, Byte[]) |
Sends a byte array to the resource, without blocking the calling thread. |
WebClient.UploadFile(string, string) |
Sends a local file to the resource and returns a byte array containing any response. |
WebClient.UploadFileAsync(Uri, string) |
Sends a local file to the resource, without blocking the calling thread. |
WebClient.UploadValues(string, System.Collections.Specialized.NameValueCollection) |
Sends a System.Collections.Specialized.NameValueCollection to the resource and returns a byte array containing any response. |
WebClient.UploadValuesAsync(Uri, System.Collections.Specialized.NameValueCollection) |
Sends a System.Collections.Specialized.NameValueCollection to the resource and returns a byte array containing any response, without blocking the calling thread. |
erload:System.Net.WebClient.UploadString |
Sends a string to the resource, without blocking the calling thread. |
erload:System.Net.WebClient.UploadStringAsync |
Sends a string to the resource, without blocking the calling thread. |
The following table describes System.Net.WebClient methods for downloading data from a resource.
WebClient.OpenRead(string) |
Returns the data from a resource as a System.IO.Stream. |
WebClient.OpenReadAsync(Uri) |
Returns the data from a resource, without blocking the calling thread. |
WebClient.DownloadData(string) |
Downloads data from a resource and returns a byte array. |
WebClient.DownloadDataAsync(Uri) |
Downloads data from a resource and returns a byte array, without blocking the calling thread. |
WebClient.DownloadFile(string, string) |
Downloads data from a resource to a local file. |
WebClient.DownloadFileAsync(Uri, string) |
Downloads data from a resource to a local file, without blocking the calling thread. |
WebClient.DownloadString(string) | |
erload:System.Net.WebClient.DownloadStringAsync |
Downloads a string from a resource, without blocking the calling thread. |
You can use the WebClient.CancelAsync method to cancel asynchronous operations that have not completed.
A System.Net.WebClient instance does not send optional HTTP headers by default. If your request requires an optional header, you must add the header to the WebClient.Headers collection. For example, to retain queries in the response, you must add a user-agent header. Also, servers may return 500 (Internal Server Error) if the user agent header is missing.
HttpWebRequest.AllowAutoRedirect is set to true in System.Net.WebClient instances.