March 2002
Intermediate to advanced
864 pages
31h 8m
English
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);
}
}