How can I set my HttpsURLConnection to trust a specific certificate only? Currently my code is set to trust all certificates. But the requirement is to trust only a specific certificate and do not trust the others. How can I do it in Java? I’m using JDK 1.5.
How can I set my HttpsURLConnection to trust a specific certificate only? Currently my
Share
You can trust a specific certificate by creating a custom SSLSocketFactory and providing your own TrustManager. See…
Trusting all certificates using HttpClient over HTTPS
and
How can I use different certificates on specific connections?
In your TrustManager, you will be handed the certificate chain from the client / server to verify against your specific certificate.