I want to connect URL via proxy server but when I am using proxy and try to get response it returns (403) Forbidden .
Without proxy everything works .
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);
}
I think the proxy ("41.217.193.6", 80) needs authentication. If you try a new proxy, the code above works. For example, at the time of writing, the following proxy works.
webRequest.Proxy = new WebProxy("200.61.168.141", 8080);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.