I need to connect to a URL over HTTPS using Java. I don't have any experience with SSL certificates, and most of the questions here assume some basic knowledge. I was hoping someone here could get me started on the basics.
When I put the URL in my browser, it connects just fine. When I do it using Java:
new URL("https://mysite.com/").openStream()
it throws 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
This question shows how to ignore the whole certificate thing, but that doesn't feel right. I simply want to use the same certificate my browser does.
I've already tried adding the -Djavax.net.ssl.trustStore=cacerts
property, which changes the exception to javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
, which I've taken from this question to mean it can't find the trust store called cacerts
. I'm not sure what else to specify, though.