WebClient & Proxy Example
Example of using webclient and proxy to get web page
static void Main(string[] args)
{
GetWebPageWithProxy("proxy", "8080","dayang.sun", "toyota#2");
}
private static void GetWebPageWithProxy(string proxyname,string proxyport, string username,string pwd)
{
// create a string with proxy name and open port to make a webproxy
string proxyinfo = string.Format("http://{0}:{1}", proxyname, proxyport);
WebProxy myProxy = new WebProxy(proxyinfo, true);
//username and password for proxy
myProxy.Credentials = new NetworkCredential(username,pwd);
WebClient webClient = new WebClient();
webClient.Proxy = myProxy;
webClient.Encoding = Encoding.UTF8;
Uri loginPageUri = new Uri("http://www.google.com");
string html = webClient.DownloadString(loginPageUri);
}
0 Comments:
Post a Comment
<< Home