Добавление файлов .pem в apache httpclientJAVA

Программисты JAVA общаются здесь
Anonymous
Добавление файлов .pem в apache httpclient

Сообщение Anonymous »

Мне нужно добавить эти 3 файла PEM (ca.pem, key.pem и cert.pem ) для моего клиента HTTP, чтобы получить доступ к службе клиента.
File caFile = new File(getClass().getResource("/certs/ca.pem").getPath());
File keyFile = new File(getClass().getResource("/certs/key.pem").getPath());
File certFile = new File(getClass().getResource("/certs/cert.pem").getPath());

SSLContext sslContext = new SSLContextBuilder()
.loadTrustMaterial(null, ( certificate, authType ) -> true).build();

CloseableHttpClient httpClient = HttpClients.custom()
.setSSLContext(sslContext)
.setSSLHostnameVerifier(new NoopHostnameVerifier())
.addInterceptorFirst((HttpRequestInterceptor) ( httpRequest, httpContext ) -> {
httpRequest.setHeader("Content-Type", "application/xml");
})
.build();

HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);


Подробнее здесь: https://stackoverflow.com/questions/761 ... httpclient

Вернуться в «JAVA»