V
V
vbNoName2018-09-26 15:56:05
Java
vbNoName, 2018-09-26 15:56:05

How to send http request with SSL certificates?

There is a PHP script like this

$ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POST,true);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
        curl_setopt($ch, CURLOPT_HEADER,0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,30);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
        curl_setopt($ch, CURLOPT_SSLCERT,PUBLIC_ENCODE_KEY__);
        curl_setopt($ch, CURLOPT_SSLKEY,PRIVATE_KEY__);
        curl_setopt($ch, CURLOPT_SSLKEYPASSWD,PASSWORD__);
        $dt = curl_exec($ch);


Help to remake it to send a request from java. Now I do it like this

HttpClient client = HttpClientBuilder.create().build();
                HttpPost request = new HttpPost("...");
                request.addHeader(new BasicHeader("Content-Type", "application/pkcs7-mime"));
                request.setEntity(new StringEntity(data, "UTF-8"));
                HttpResponse response = client.execute(request);
                log.info("Response status code: {}", response.getStatusLine().getStatusCode());
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent()));
                    StringBuilder result = new StringBuilder();
                    String line = "";
                    while ((line = bufferedReader.readLine()) != null) {
                        result.append(line);
                    }
                    return result.toString();
                }


But I am getting an error

javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure


Actually, the question is how and where to add these SSL certificates?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question