1.restTemplate或者httpClient没有特殊配置访问https接口的话会报这个错
Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://XXXXX": sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:670)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:414)
at com.gongfuhaoche.sms.common.config.AppConfig.main(AppConfig.java:99)
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHand
访问https无有效证书:unable to find valid certification path to requested target 问题解答
最新推荐文章于 2024-04-09 18:03:24 发布
当使用RestTemplate或HttpClient访问HTTPS接口时,可能会遇到'PKIX path building failed'错误,该错误是由于无法找到有效的证书路径导致的SSLHandshakeException。解决方法包括:1. 引入httpclient包并进行特殊配置,跳过SSL证书验证;2. 如果使用连接池,需要特别配置连接池以忽略SSL验证。参考Stack Overflow相关文档可获取详细步骤。
摘要由CSDN通过智能技术生成