使用代理访问远程服务

时间:2015-01-31 10:29:56   收藏:0   阅读:161
string getHost = "http://www.cnblogs.com";

WebClient wClient = new WebClient();
WebProxy p = null; //代理类

string proxyAddressAndPort = "openproxy.tt.com:8080";
string proxyUserName = Class1.u;
string proxyPwd = Class1.p;

ICredentials cre = new NetworkCredential(proxyUserName, proxyPwd); //得到用户名和密码
p = new WebProxy(proxyAddressAndPort, true, null, cre); //将信息放于代理类中(代理服务器URl,是否跳过代理,,身份验证信息)
WebRequest.DefaultWebProxy = p; //为Web请求设置代理

string retval = wClient.DownloadString(getHost);

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!