调用Https接口时--未能创建SSL/TLS安全通道问题解决方式原创
1人赞赏了该文章
5,128次浏览
编辑于2022年08月31日 18:21:22
场景:使用纯HttpPost调用接口(不论是WebService、还webAPI),如果接口地址是Https开头,则容易出现此问题。如下图
解决办法是:增加安全通道。代码如下
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true; }
赞 1
1人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读
您的鼓励与嘉奖将成为创作者们前进的动力,如果觉得本文还不错,可以给予作者创作打赏哦!
请选择打赏金币数 *
10金币20金币30金币40金币50金币60金币
可用金币: 0