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

前端之家收集整理的这篇文章主要介绍了c# – WebProxy错误:需要代理验证前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用以下代码来访问互联网上的html数据:
  1. WebProxy p = new WebProxy("localproxyIP:8080",true);
  2. p.Credentials = new NetworkCredential("domain\\user","password");
  3. WebRequest.DefaultWebProxy = p;
  4. WebClient client = new WebClient();
  5. string downloadString = client.DownloadString("http://www.google.com");

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

@H_502_9@

解决方法

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

猜你在找的C#相关文章