首页 > 代码库 > 使用代理访问远程服务

使用代理访问远程服务

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);

 

使用代理访问远程服务