C# 访问https 未能创建 SSL/TLS 安全通道

C# 访问https请求被中止: 未能创建 SSL/TLS 安全通道(Could not create SSL/TLS secure channel)

一般GetResponse可以直接访问https,如果不行添加回调:

ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
还不行, 添加:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

        public string GetHttpWebResponse(string url, string postData, string code = "utf-8")
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(code)))
{
return reader.ReadToEnd();
}
}
catch (WebException e)
{
return e.Message;
}
finally
{
if (response != null) response.Close();
}
} public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}

  

上一篇:leaflet-velocity 参数


下一篇:jquery点击元素之外触发事件