Skip to content

Including a .pem certificate in a Java HTTP request

I am currently able to access a web service that requires a client certificate using the following curl command:

curl -k -v –cert ./certificate.pem

How do I make this request in a Java application?

Notice that I need the -k flag which allows curl to make “insecure” SSL connections. This needs to be done in the Java application as well.



The solution to this problem was to include the server’s certificates in the Java trust store.

To download and import the above certificates of the server I used InstallCert Java code from GitHub.

The keyStore and trustStore were then defined in system properties like below:$JAVA_HOME/jre/lib/security/cacerts"
User contributions licensed under: CC BY-SA
5 People found this is helpful