未能创建 SSL/TLS 安全通道

调用一个人脸识别的接口报错 未能创建 SSL/TLS 安全通道 提那家如下就可以,这里需要注意的是 .net framework 4.0之前的要特别注意一下 如下

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                       | SecurityProtocolType.Tls
                                       | SecurityProtocolType.Tls11
                                       | SecurityProtocolType.Tls12;

但如果客户端是基于.net framework 4.0或更早版本的,SecurityProtocolType枚举中并没有Tls11和Tls12,这就需要直接填值:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                       | SecurityProtocolType.Tls
                                       | (SecurityProtocolType)0x300 //Tls11
                                       | (SecurityProtocolType)0xC00; //Tls12

如此即可。

事实上,这个问题正是因为我的客户端是基于.net 4.0的,而4.0的ServicePointManager.SecurityProtocol默认就不含Tls11和Tls12,所以当服务端改用这两种安全协议时,自然访问不了。

 

引自 https://cloud.tencent.com/developer/article/1403744

posted on 2019-07-30 16:25  木子十三  阅读(710)  评论(0编辑  收藏  举报

导航