首页 > 编程知识 正文

无法执行ssl通讯,无法安全的连接到此页面tls

时间:2023-05-03 19:09:09 阅读:134269 作者:4205

前言最近负责应对第三方服务。 在坞站中,第三方服务是https请求,因此已知当请求https时,它会使用本地证书公钥访问服务SSL证书。 无法请求服务,因为我的本地没有对应的SSL证书。 向接口时报请求类似以下的错误。 资源的发现可以忽略SSL认证。

unabletofindvalidcertificationpathtorequestedtarget

一.创建RestTemplate配置类

@ configurationpublicclassresttemplateconfig { @ beanpublicresttemplateresttemplate () (generatehttplate ) }/***SSL证书* @ return */privatehttpcomponentsclienthttprequestfactorygeneratehttprequestfactory () trustrategyaccccess SSS try { sslcontext=sslcontext s.custom (.loadtrustmaterial (null,acceptingTrustStrategy ).build ); } catch (nosuchalgorithmexceptione ) { e.printStackTrace ); }缓存(keymanagementexceptione ) { e.printStackTrace ); }catch(keystoreexceptione ) { e.printStackTrace ); } sslconnectionsocketfactoryconnectionsocketfactory=newsslconnectionsocketfactory (sslcontext,new NoopHostnameVerifier ) ) httpclientbuilderhttpclientbuilder=http clients.custom (; http客户端构建器. setsslsocketfactory (connectionsocketfactory ); closeablehttpclienthttpclient=http client builder.build (tttpcomponentsclienthttprequestfactoryfactory=newhtttpcomponentscld ) factory.set http客户端(http客户端; 返回工厂; (二)建立测试类

@ springboottestpublicclassignoressltest { @ autowiredprivateresttemplateresttemplate; privatestring URL=' https://XXX.xxxx '; @ testpublicvoidtest ((/rest template用于服务调用responseentitystringresponseentity=rest template.postforentity ) URL,NUE }根据测试结果,验证是否成功请求了接口,并忽略SSL证书。

当然有安装证书等很多方法。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。