public class WebClient : Component
The WebClient
class provides easy access to resources over HTTP, FTP, and File protocols. It simplifies common tasks such as downloading files, uploading data, and making asynchronous requests.
This class is thread-safe. You can use multiple instances of WebClient
in a single thread, or you can use a single instance in multiple threads.
For more advanced scenarios, consider using HttpClient
.
Initializes a new instance of the WebClient
class.
public virtual void DownloadFile(string address, string fileName);
Downloads the resource with the specified URI to a local file.
public virtual string DownloadString(string address);
Returns the response body as a string from the specified URI.
public virtual byte[] UploadFile(string address, string fileName);
Uploads the specified local file to the specified resource.
public virtual string UploadString(string address, string data);
Uploads the specified string to the specified resource.
public virtual void DownloadFileAsync(Uri address, string fileName);
Initiates an asynchronous operation to download the resource with the specified URI to a local file.
public virtual void DownloadStringAsync(Uri address);
Initiates an asynchronous operation to download the resource with the specified URI.
public virtual void UploadFileAsync(Uri address, string fileName);
Initiates an asynchronous operation to upload the specified local file to the specified resource.
public virtual void UploadStringAsync(Uri address, string data);
Initiates an asynchronous operation to upload the specified string to the specified resource.
public virtual string BaseAddress { get; set; }
Gets or sets the base address of the Uniform Resource Identifier (URI) that is used for requests.
public virtual System.Text.Encoding Encoding { get; set; }
Gets or sets the encoding that is used to upload and download text.
public virtual System.Net.WebHeaderCollection Headers { get; }
Gets the collection of HTTP headers associated with the request.
public bool IsBusy { get; }
Gets a value indicating whether the asynchronous operation is in progress.
public virtual System.Collections.Specialized.NameValueCollection QueryString { get; set; }
Gets or sets the query string parameters to append to the URI.
public event System.Net.DownloadFileCompletedEventHandler DownloadFileCompleted;
Occurs when a file transfer is completed.
public event System.Net.DownloadProgressChangedEventHandler DownloadProgressChanged;
Occurs when the progress of an asynchronous file transfer is updated.
public event System.Net.UploadFileCompletedEventHandler UploadFileCompleted;
Occurs when a file upload is completed.
public event System.Net.UploadProgressChangedEventHandler UploadProgressChanged;
Occurs when the progress of an asynchronous file upload is updated.