zl程序教程

您现在的位置是:首页 >  云平台

当前栏目

使用代理访问远程服务

代理服务 远程 访问 使用
2023-09-11 14:21:36 时间
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);