Home >Java >javaTutorial >How to Fix \'PKIX path building failed: unable to find valid certification path to requested target\' in Java?
PKIX Path Building Failure: Resolving Invalid Certification Path
When attempting to connect to an HTTPS endpoint using Java's standard HttpClient library, you encountered an exception stating: "PKIX path building failed: unable to find valid certification path to requested target." This indicates that the client is unable to establish a secure TLS connection due to issues related to certificate verification.
Potential Causes:
Solution: Configuring a TrustStore
To resolve this issue, you need to ensure that the client's trust store includes the certificate of the trusted root CA that issued the server's certificate. You can use the System.setProperty() method to set the javax.net.ssl.trustStore and javax.net.ssl.trustStorePassword properties, which will point to the path and password of your trust store.
The following code demonstrates how to set these properties:
<code class="java">System.setProperty("javax.net.ssl.trustStore","clientTrustStore.key"); System.setProperty("javax.net.ssl.trustStorePassword","qwerty");</code>
Once you have set the trust store properties, the client will be able to verify the server's certificate and establish a secure connection.
Note on Certificates:
The above is the detailed content of How to Fix \'PKIX path building failed: unable to find valid certification path to requested target\' in Java?. For more information, please follow other related articles on the PHP Chinese website!