0

I am trying to send a HTTP POST request to a site with a HTTPS proxy.

I am currently doing it like that:

System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
HttpPost request = new HttpPost("https://example.com");

                    HttpHost proxy2 = new HttpHost("proxy ip here", 8080, "https");
                    RequestConfig config = RequestConfig.custom()
                            .setProxy(proxy2)
                            .build();
                    request.setConfig(config);


                    String json = "\"" + username + "\"";
                    StringEntity entity = new StringEntity(json);
                    request.setEntity(entity);
                    request.setHeader("Accept", "application/json");
                    request.setHeader("Content-type", "application/json");

                    CloseableHttpResponse response = httpclient.execute(request, context);

                    HttpEntity entityresponse = response.getEntity();
                    responseString = EntityUtils.toString(entityresponse, "UTF-8");

                    response.close();
                    httpclient.close();

But I am getting this: java.net.SocketException: Connection reset

I've tried a lot of proxies and different URLs too but the same problem is there.

It work fine if I set a HTTP URL and the http parameter in the proxy host line, but I want HTTPS :/

Any help would be appreciated.

Thanks!

1 Answer 1

1

If you want to call https url, you must have to install the certificate in your jre security/lib folder.

In order to install the certificate, please follow below steps:

  1. Download InstallCert.java file from : https://confluence.atlassian.com/download/attachments/180292346/InstallCert.java?version=1&modificationDate=1315453596921
  2. copy InstallCert.java to any location.
  3. run: javac InstallCert.java
  4. run: java InstallCert example.com:port
  5. jssecacerts file will be generated
  6. Copy it inside JAVA_HOME\jre\lib\security folder

I hope this should resolve your issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.