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)需要代理身份验证。我不知道该怎么办,有人可以给我一些建议吗?
答案 0 :(得分:2)
试试这个:
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标头。