我使用以下代码从互联网获取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");但出现以下错误:"Proxy Authentication Required“。我不能使用默认代理,因为我的代码运行在windows服务的特殊帐户下,没有默认的代理设置。所以,我想在我的代码中指定所有的代理设置。请建议我如何解决这个错误。
发布于 2012-10-22 18:08:29
您必须设置WebClient.Proxy属性..
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");发布于 2013-06-19 17:02:16
这对我很有效:
IWebProxy defaultWebProxy = WebRequest.DefaultWebProxy;
defaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
client = new WebClient
{
Proxy = defaultWebProxy
};
string downloadString = client.DownloadString(...);发布于 2012-10-22 18:05:36
试试这段代码
var transferProxy = new WebProxy("localproxyIP:8080", true);
transferProxy.Credentials = new NetworkCredential("user", "password", "domain");
var transferRequest = WebRequest.Create("http://www.google.com");
transferRequest.Proxy = transferProxy;
HttpWebResponse transferResponse =
(HttpWebResponse)transferRequest.GetResponse();
System.IO.Stream outputStream = transferResponse.GetResponseStream();https://stackoverflow.com/questions/13008964
复制相似问题