我想通过代理服务器连接URL,但当我使用代理并尝试获取响应时,它返回(403)Forbidden。
没有代理,一切正常。
private void button1_Click(object sender, EventArgs e)
{
CookieContainer cookies = new CookieContainer();
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://wikipedia.com");
webRequest.Proxy = new WebProxy("41.217.193.6", 80);
webRequest.CookieContainer = cookies;
webRequest.Accept = "*/*";
webRequest.Timeout = 9000;
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse(); /// <== The remote server returned an error: (403) Forbidden.
StreamReader responseReader = new StreamReader(response.GetResponseStream());
string sResponseHTML = responseReader.ReadToEnd();
Clipboard.SetText(sResponseHTML);
}
答案 0 :(得分:0)
我认为代理(“41.217.193.6”,80)需要身份验证。如果您尝试新的代理,上面的代码可以正常工作。例如,在撰写本文时,以下代理可以正常工作。
webRequest.Proxy = new WebProxy("200.61.168.141", 8080);