阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

解决Linux netcore https请求使用自签名证书忽略安全检查方法

165次阅读
没有评论

共计 1358 个字符,预计需要花费 4 分钟才能阅读完成。

当前系统环境:CentOS 7 x64. dotnet 2.0.
不管是
ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true;
还是:
HttpClient httpClient = new HttpClient(new HttpClientHandler() {ServerCertificateCustomValidationCallback = (a, b, c, d) => true });

都会发生错误:
错误信息大致如下:
(The handler does not support custom handling of certificates with this combination of libcurl (7.29.0) and its SSL backend (“NSS/3.28.4”).) —> System.PlatformNotSupportedException: The handler does not support custom handling of certificates with this combination of libcurl (7.29.0) and its SSL backend (“NSS/3.28.4”).
 at System.Net.Http.CurlHandler.SslProvider.SetSslOptionsForUnsupportedBackend(EasyRequest easy, ClientCertificateProvider certProvider)
 at System.Net.Http.CurlHandler.SslProvider.SetSslOptions(EasyRequest easy, ClientCertificateOption clientCertOption)

解决方案:

# yum update(可选)
# yum install openssl-devel gcc #安装 openssl 和 gcc

# 安装指定版本的 curl
# wget https://curl.haxx.se/download/curl-7.55.1.tar.gz
# tar -zxf curl-7.55.1.tar.gz
# cd curl-7.55.1
# ./configure –prefix=/usr/local/curl/ –without-nss –with-ssl=/usr/local/ssl/
# make
# make install

# 备份原来的 curl
mv /usr/bin/curl /usr/bin/curl.bak

# 将安装的 curl 创建软连
ln -s /usr/local/curl/bin/curl /usr/bin/curl
#  curl –version
# 差不多输出下面的内容
#curl 7.55.1 (x86_64-pc-linux-gnu) libcurl/7.55.1 OpenSSL/1.0.2k zlib/1.2.7

# 增加 lib 搜索目录
# vi /etc/ld.so.conf
# 增加
# /usr/local/curl/lib
# cat /etc/ld.so.conf
差不多下面这样子
#
include ld.so.conf.d/*.conf
/usr/local/curl/lib

# 重新 load 配置
# ldconfig

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计1358字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中