我使用HttpClient从Java文件调用rest API。通过使用它,我可以调用http API,但不能调用https API。
我得到下面的错误,而调用httpsapi。
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:1946)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:316)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:310)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1639)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:223)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1037)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:965)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1064)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
字符串
我想使用CloseableHttpClient
调用https API。
我的证书文件中有私钥。请告诉我如何使用私钥调用API?
1条答案
按热度按时间aydmsdu91#
要使用
https
调用API,您需要配置SSLContext
并将其设置为您的HttpClient
。请参考下面的示例代码。这只是示例,您可以以不同的方式加载keystore和truststore,例如从classpath,form file system等。,进行相应的更改。字符串