自己署名証明書を使用しているサーバーに Https Post リクエストを送信しようとしていますが、次のエラーで例外が発生します: peer not authenticated
.
問題の原因は、サーバーが自己署名証明書を使用していることです。どうすればこのエラーを抑制できますか?
次の関数を使用して投稿リクエストを送信しています。
public String sendPost(final String request, final String postData) throws ClientProtocolException, IOException {
String result = null;
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(request);
ByteArrayEntity postDataEntity = new ByteArrayEntity(postData.getBytes());
httpPost.setEntity(postDataEntity);
CloseableHttpResponse response = httpclient.execute(httpPost);
try {
HttpEntity entity = response.getEntity();
result = EntityUtils.toString(entity);
EntityUtils.consume(entity);
} finally {
response.close();
}
return result;
}
このエラーを抑制するために何が欠けていますか? この例外をキャッチしようとはしません。自己署名証明書が受け入れられるように適切に構成したい。私はHttpclient 4.1を使用しています。
ありがとう!