using system;
using system.net;
using system.text;
using system.collections.specialized;
public class webclientsample
{
public static void main()
{
try {
// download the data to a buffer
webclient client = new webclient();
byte[] pagedata = client.downloaddata("http://www.microsoft.com");
string pagehtml = encoding.ascii.getstring(pagedata);
console.writeline(pagehtml);
// download the data to a file
client.downloadfile("http://www.bn.com", "page.htm");
// upload some form post values
namevaluecollection form = new namevaluecollection();
form.add("myname", "myvalue");
byte[] responsedata = client.uploadvalues("http://localhost/somefile.aspx", form);
}
catch (webexception webex) {
console.writeline(webex.tostring());
if(webex.status == webexceptionstatus.connectfailure) {
console.writeline("are you behind a firewall? if so, go through the proxy server.");
}
}
}
}
