X509TrustManager trustManager = new X509TrustManager(){
@Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
SSLContext sc = SSLContext.getInstance(“TLSv1.2”);
sc.init(null, new TrustManager[] { trustManager }, null);
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sc);
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
HttpGet get = new HttpGet(tempURL);
CloseableHttpResponse response = httpclient.execute(get);
HttpEntity entity = response.getEntity();
int responseStauts = response.getStatusLine().getStatusCode();
if(responseStauts == 200){
String result= EntityUtils.toString(entity, UTF_8);
}
HttpClient访问Https
最新推荐文章于 2023-11-23 09:01:17 发布