[英]proxy error requesting https
I am using this little piece of code to access remote Uri's : 我正在使用这段代码来访问远程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;
This is working perfectly for all "http" Uri. 这对于所有“ http” Uri都非常有效。 However, when switching to the following type of Uri's (https), i am getting a proxy error 407 requesting authentification (log of the Exception tells that credentials are bad).
但是,当切换到以下类型的Uri(https)时,我收到请求身份验证的代理错误407(“异常”日志表明凭据无效)。 Do you have any idea of how i could handle this ?
您是否知道我该如何处理?
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;
Best regards, 最好的祝福,
Al_th Al_th
Try this 尝试这个
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.