码迷,mamicode.com
首页 > Web开发 > 详细

https网站访问第三方https网站时候报错: The request was aborted:Could not create SSL/TLS secure channel.

时间:2020-01-04 20:37:04      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:第三方   style   not   policy   manager   ret   channel   nbsp   server   

https网站访问第三方https网站时候报错:

The request was aborted:Could not create SSL/TLS secure channel.

 

解决办法:

if(Url.StartsWith("https",StringComparison.OrdinalIgnoreCase))//https请求
                {
                    ServicePointManager.Expect100Continue = true;
                    //如果是4.5以上版本可以直接使用
                    //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
                    //                                        | SecurityProtocolType.Tls11
                    //                                        | SecurityProtocolType.Tls
                    //                                        | SecurityProtocolType.Ssl3;
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
                                                            | (SecurityProtocolType)768
                                                            | (SecurityProtocolType)3072
                                                            | SecurityProtocolType.Ssl3;
                    ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
                    request = WebRequest.Create(Url_Temp) as HttpWebRequest;
                    request.ProtocolVersion = HttpVersion.Version10;
                }
                else
                {
                    request = WebRequest.Create(Url_Temp) as HttpWebRequest;
                }

 回调函数:

    private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    {
        //为了通过证书验证,总是返回true
        return true;
    }

 

https网站访问第三方https网站时候报错: The request was aborted:Could not create SSL/TLS secure channel.

标签:第三方   style   not   policy   manager   ret   channel   nbsp   server   

原文地址:https://www.cnblogs.com/kevin860/p/12150043.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!