How to pass ssl certificates with GET REST API call

تعرفه تبلیغات در سایت

آرشیو مطالب

امکانات وب

Vote count: 0

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("", "/Users/rc/Downloads/test101/jks/keystore.jks");

System.setProperty("", "asdfgh");
System.setProperty("", "JKS");            


        //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: Unexpected end of file from server at this line :
    int responseCode = con.getResponseCode();   
asked 39 secs ago

نویسنده : استخدام کار بازدید : 0 تاريخ : چهارشنبه 22 فروردين 1397 ساعت: 5:29
برچسب‌ها :



نام کاربري :
رمز عبور :