加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – WebProxy错误:需要代理验证

发布时间:2020-12-15 17:36:05 所属栏目:百科 来源:网络整理
导读:我使用以下代码来访问互联网上的html数据: WebProxy p = new WebProxy("localproxyIP:8080",true);p.Credentials = new NetworkCredential("domainuser","password");WebRequest.DefaultWebProxy = p;WebClient client = new WebClient();string download
我使用以下代码来访问互联网上的html数据:
WebProxy p = new WebProxy("localproxyIP:8080",true);
p.Credentials = new NetworkCredential("domainuser","password");
WebRequest.DefaultWebProxy = p;
WebClient client = new WebClient();
string downloadString = client.DownloadString("http://www.google.com");

但是出现以下错误:“需要代理验证”.
我不能使用默认代理,因为我的代码从没有默认代理设置的特殊帐户下的Windows服务运行.
所以,我想标明我的代码中的所有代理设置.
请告诉我如何解决这个错误.

解决方法

你必须设置WebClient.Proxy属性..
WebProxy p = new WebProxy("localproxyIP:8080","password");
WebRequest.DefaultWebProxy = p;
WebClient client = new WebClient();
**client.Proxy = p;**
string downloadString = client.DownloadString("http://www.google.com");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读