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

我使用以下代码来访问互联网上的html数据:
WebProxy p = new WebProxy("localproxyIP:8080",true);
p.Credentials = new NetworkCredential("domain\\user","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");

相关文章

原文地址:http://msdn.microsoft.com/en-us/magazine/cc163...
前言 随着近些年微服务的流行,有越来越多的开发者和团队所采...
最近因为比较忙,好久没有写博客了,这篇主要给大家分享一下...
在多核CPU在今天和不久的将来,计算机将拥有更多的内核,Mic...
c语言输入成绩怎么判断等级
字符型数据在内存中的存储形式是什么