[英]proxy error requesting https
我正在使用這段代碼來訪問遠程Uri:
Uri uri = "http://www.myurl.com";
WebRequest wreq = WebRequest.Create(uri);
((HttpWebRequest)wreq).UserAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.75 Safari/537.1";
wreq.Proxy = WebRequest.DefaultWebProxy;
這對於所有“ http” Uri都非常有效。 但是,當切換到以下類型的Uri(https)時,我收到請求身份驗證的代理錯誤407(“異常”日志表明憑據無效)。 您是否知道我該如何處理?
Uri uri = "https://www.myurl.com";
WebRequest wreq = WebRequest.Create(uri);
((HttpWebRequest)wreq).UserAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.75 Safari/537.1";
wreq.Proxy = WebRequest.DefaultWebProxy;
最好的祝福,
Al_th
嘗試這個
private string GetPageSource(string url)
{
string htmlSource = string.Empty;
try
{
System.Net.WebProxy myProxy = new System.Net.WebProxy("Proxy IP", 8080);
using (System.Net.WebClient client = new System.Net.WebClient())
{
client.Proxy = myProxy;
client.Proxy.Credentials = new System.Net.NetworkCredential("username", "password");
htmlSource = client.DownloadString(url);
}
}
catch (WebException ex)
{
// log any exceptions
}
return htmlSource;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.