2012-03-10 53 views
0

我想通過代理服務器連接URL,但是當我使用代理並嘗試獲取響應時,它返回(403)禁止。WebRequest代理 - 403禁止錯誤

沒有代理一切正常。

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); 
    } 
+1

您是否設置了請求的憑據? – 2012-03-10 09:26:00

回答

0

我認爲代理(「41.217.193.6」,80)需要認證。如果你嘗試一個新的代理,上面的代碼工作。例如,在撰寫本文時,以下代理工作。

webRequest.Proxy = new WebProxy("200.61.168.141", 8080);