I have a webserver running on different machine. I am able to use postman client and load cert.pem and key.pem files and successfully do a get request.
Now I want to do this programatically in Java. To do that I added the P12 to keystore as below :
keytool -importkeystore -destkeystore keystore.jks -srcstoretype PKCS12 -srckeystore keystore.p12
keytool -list -keystore keystore.jks
Now in the code I did this:
String url = "http://localhost:9443/server/api/v1/"+id+"/_history/"+history;
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
System.setProperty("javax.net.ssl.keyStore", "/Users/rc/Downloads/test101/jks/keystore.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "asdfgh");
System.setProperty("javax.net.ssl.keyStoreType", "JKS");
con.setRequestMethod("GET");
//add request header
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json");
int responseCode = con.getResponseCode();
System.out.println("nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
I am getting:
java.net.SocketException: Unexpected end of file from server at this line :
int responseCode = con.getResponseCode();