【问题标题】:Downloading website html content using WebClient issues a 407 response, why?使用 WebClient 下载网站 html 内容会发出 407 响应,为什么?
【发布时间】:2011-07-26 17:12:19
【问题描述】:
public const string url = 
"http://www.londonstockexchange.com/exchange/prices-and-markets/international-markets/indices/home/ftse-mib.html";

public static void Main(String[] args)
{
    WebClient wc = new WebClient();
    string s = wc.DownloadString(url);
}

当我运行此代码时,我收到错误消息:远程服务器返回错误:(407) 需要代理身份验证。我不知道该怎么办,谁能给我一些建议?

【问题讨论】:

  • 您好!你似乎没有接受你的问题的任何答案。请参阅stackoverflow.com/faq,了解如何以及为什么这样做。如果您没有得到任何满意的答案,请尝试提出更简单、更切题的问题。
  • 给出一个推测性的答案 - 你可能会得到这个错误,因为 LSE 想要阻止爬虫在不支付许可证的情况下收集他们的数据。

标签: .net webclient


【解决方案1】:

试试这个:

WebClient wc = new WebClient();
wc.Headers.Add("user-agent", "Testing...");

WebProxy proxyObject = new WebProxy(url); 
proxyObject.Credentials = CredentialCache.DefaultCredentials;
wc.Proxy = proxyObject;

string s = wc.DownloadString(url);

请参考this link 了解 WebClient 标头。

【讨论】:

  • 您好 Knvn,当我尝试此代码时,我无法连接到远程服务器
  • 你在 WebProxy 上得到这个吗?什么是内部异常?
猜你喜欢
  • 1970-01-01
  • 2017-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-29
  • 2010-12-13
相关资源
最近更新 更多