首页 > Web开发 > 详细

HttpClient SSL connection could not be established error

时间:2019-07-04 19:45:02      阅读:309      评论:0      收藏:0      [点我收藏+]

系统从.net framework 升级到dotnet core2.1 

原先工作正常的httpclient,会报SSL connection could not be established error 错误 

 

在.net framework中通过ServicePointManager,当证书出错时,可以跳过证书验证。

ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true

升级到dotnet core 2.1后,发现以上配置无效。

  原因是ServicePointManager只对HttpWebRequest有效,.net framework中httpclient是基于HttpWebRequest实现的,所以Httpclient不会报错

在dotnetcore2.1中,Httpclient想要实现相同的功能,需要在HttpClient中设置。

 var handler = new HttpClientHandler
 {
     ServerCertificateCustomValidationCallback = delegate { return true; }
 };

github上有人提过这个问题,可以参见 https://github.com/dotnet/corefx/issues/29452

HttpClient SSL connection could not be established error

原文:https://www.cnblogs.com/chenzhenfj/p/11134042.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!