Download data
WebClient WC = new WebClient ();
1 string str= WC. Downloadstring ("Address");//download string directly
2 WC. DownloadFile ("Addredd", "fileName");//Download the file and specify the address to download to
3 byte[] B=WC. Downloaddata ("Address")//return a binary array directly and then convert
Wc. Dispose ();
Uploading data
String poststring = "arg1=a&arg2=b"; Here is the parameters passed, you can use the tool to grasp the packet analysis, but also to analyze themselves, mainly in the form of each name to add in byte[] postdata = Encoding.UTF8.GetBytes ( poststring); //coding, especially Chinese characters, in advance to see how to crawl the page encoding
WebClient WebClient = new WebClient ();
WEBCLIENT.HEADERS.ADD ("Content-type", "application/x-www-form-urlencoded"); //Take the header that must be added to the post, and if you change it to get it, remove the phrase byte[] responsedata = webclient.uploaddata ("url", "POST", postdata); Gets the return character stream string srcstring = Encoding.UTF8.GetString (responsedata); Decoding
C # WebClient implement upload and download network resources