我正在尝试编写一个安静的客户端来使用 https 服务。我们正在使用客户端共享的 jks 文件。当我将 jks 文件与soap ui 一起使用时。即,将其添加为 sslkeystore,我得到了成功响应。但是在使用 closeablehttpclient 时,我得到了 401 异常。
代码片段如下
SSLContextbuilder sslBuilder = SSLContexts.custom();
File file = new File(Keystorepass);
SSLBuilder = SSLBuilder.loadTrustMaterial(file, KEYSTOREPASS.toCharArray());
SSLContext sslContext = SSLBuilder.build();
HttpClientBuilder clientBuilder = HttpClients.custom();
clientBuilder.setSSLContext(sslContext);
CloseableHttpClient client = clientBuilder build();
HttpPost httpPost = new HttpPost(url);
HttpEntity entity = new ByteArrayEntity(reqXML.getBytes("UTF-8");
httpPost.setEntity(entity);
response = client.execute(httpPost);