WebException: The SSL connection could not be established, see inner exception. The remote certificate is invalid according to the validation procedure.
WebException: The SSL connection could not be established, see inner exception. The remote certificate is invalid according to the validation procedure.
代码如下:
HttpWebRequest request = null;
request = (HttpWebRequest)WebRequest.Create(pURLIn);
request.AllowAutoRedirect = true;
request.Timeout = 20000;
request.MaximumAutomaticRedirections = 10;
request.Method = "GET";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36";
request.Accept = " text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
//不保持连接
request.KeepAlive = false;
// 获取对应HTTP请求的响应
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
return response.ResponseUri.OriginalString;
}
else
{
return response.StatusDescription;
}
开发状态下,临时处理(或者没什么特殊安全要求的情况下最简单处理):
ServicePointManager.ServerCertificateValidationCallback =
delegate(object sender, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslPolicyErrors) { return true; };