1.Httpclient jar 版本:httpclient-4.5.3.jar
2.GET请求抛出异常:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException
3.GET 方法解决异常, 修改GET方法如下:
public String doHttpClientGetRequestForSSL(String request) throws ClientProtocolException, IOException {
CloseableHttpClient httpclient;
BufferedReader in = null;
String responseAsString = null;
try {
httpclient = HttpClients.custom().setSSLSocketFactory(new SSLConnectionSocketFactory(SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build())).build();
HttpUriRequest httpGet = new HttpGet(request);
CloseableHttpResponse response = httpclient.execute(httpGet);
// System.out.println(response.getStatusLine());
responseAsString = EntityUtils.toString(response.getEntity());
// System.out.println(responseAsString);
response.close();
} catch (KeyManagementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (KeyStoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return responseAsString;
}