9.4 WebClient

WebClient provides a higher-level interface to network resources than WebRequest . DownloadData( ) and DownloadFile( ) retrieve resources from a URI into a byte array or a file. UploadData( ) and UploadFile( ) sends the contents of a byte array or a file to a resource identified by a URI. Use WebClient to rewrite Snarf.cs as:

 // Snarf2.cs // Run Snarf.exe <http-uri> to retrieve a web page using System; using System.Net; using System.Text; class Snarf {   static void Main(string[ ] args) {     WebClient wc = new WebClient( );     byte[ ] buffer = wc.DownloadData(args[0]);     string doc = Encoding.ASCII.GetString(buffer);     Console.WriteLine(doc);   } } 


C# in a Nutshell
C # in a Nutshell, Second Edition
ISBN: 0596005261
EAN: 2147483647
Year: 2005
Pages: 963

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net