WebProxy错误:需要代理身份验证 [英] WebProxy error: Proxy Authentication Required
本文介绍了WebProxy错误:需要代理身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码从互联网获取html数据:
I use the following code to obtaing html data from the internet:
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服务运行,而该帐户没有默认代理设置。
因此,我想在代码中指定所有代理设置。
请建议我如何解决此错误。
But the following error is appeared: "Proxy Authentication Required". I can't use default proxy because of my code runs from windows service under the special account which there is no default proxy settings for. So, I want to specidy all proxy settings in my code. Please advice me how to resolve this error.
推荐答案
您必须设置WebClient.Proxy属性。
You've to set the WebClient.Proxy Property..
WebProxy p = new WebProxy("localproxyIP:8080", true);
p.Credentials = new NetworkCredential("domain\\user", "password");
WebRequest.DefaultWebProxy = p;
WebClient client = new WebClient();
**client.Proxy = p;**
string downloadString = client.DownloadString("http://www.google.com");
这篇关于WebProxy错误:需要代理身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文