httpclient请求https域名异常问题总结

java -jar命令启动springboot项目,解决httpclient请求https域名踩过的坑

  1. 执行如下命令访问https域名

curl --location --request GET 'http://localhost:8080/api/rest/versionmanager/internal/v1/test'

异常信息如下图

httpclient请求https域名异常问题总结

 

从上图可发现在httpclient发送https过程中出现RSA的secret异常,由于jre内置security模块,该工具包实现了加密和解密算法,jdk在执行java -jar命令时,未引入sunjce_provider.jar文件,导致解密异常。

  1. 同样java -jar执行httpclient访问https域名异常信息如下

httpclient请求https域名异常问题总结

 

此异常说明,在执行TCP握手过程中证书解析出现问题,无法实现握手操作

解决方案:

1.直接将sunjce_provider.jar包放到项目工程依赖包下

2.在命令上配置 -Djava.ext.dirs=${lib_path}::${jre_lib_ext_path}

jre_lib_ext_path为服务器安装的jre路径地址,当前路径包含sunjce_provider.jar文件