System.Net.WebClient
inherits from System.ComponentModel.Component
and is used to send and receive data to and from a URI. System.Net.Http.HttpClient
rather than S.N.WebClient
. AllowReadStreamBuffering | |
AllowWriteStreamBuffering | |
BaseAddress | |
CachePolicy | |
CancelAsync() | |
Credentials | |
DownloadData() | |
DownloadDataAsync() | |
DownloadDataTaskAsync() | |
DownloadFile() | |
DownloadFileAsync() | |
DownloadFileTaskAsync() | |
DownloadString() | |
DownloadStringAsync() | |
DownloadStringTaskAsync() | |
Encoding | |
GetWebRequest() | |
GetWebResponse() | |
Headers | |
IsBusy | |
OnDownloadDataCompleted() | |
OnDownloadFileCompleted() | |
OnDownloadProgressChanged() | |
OnDownloadStringCompleted() | |
OnOpenReadCompleted() | |
OnOpenWriteCompleted() | |
OnUploadDataCompleted() | |
OnUploadFileCompleted() | |
OnUploadProgressChanged() | |
OnUploadStringCompleted() | |
OnUploadValuesCompleted() | |
OnWriteStreamClosed() | |
OpenRead() | |
OpenReadAsync() | |
OpenReadTaskAsync() | |
OpenWrite() | |
OpenWriteAsync() | |
OpenWriteTaskAsync() | |
Proxy | |
QueryString | |
ResponseHeaders | |
UploadData() | |
UploadDataAsync() | |
UploadDataTaskAsync() | |
UploadFile() | |
UploadFileAsync() | |
UploadFileTaskAsync() | |
UploadString() | |
UploadStringAsync() | |
UploadStringTaskAsync() | |
UploadValues() | |
UploadValuesAsync() | |
UploadValuesTaskAsync() | |
UseDefaultCredentials |
System.Net.WebClient
might be used. using System; using System.Net; class M { public static void Main(String[] argv) { if (argv.Length != 1) { Console.WriteLine("Provide URL to fetch data from"); return; } var client = new WebClient(); client.Headers.Add("User-Agent", ".NET-WebClient/1.0 TQ84"); var content = client.DownloadString(argv[0]); Console.WriteLine(content); } }
C:\> WebClient.exe https://google.com
UploadFile()
method can be used to upload a file with a HTTP POST request or an FTP STOR command. SecurityProtocol
of System.Net.ServicePointManager
needs to be set to Tls12
.