Apache的HttpClient调用Https忽略证书校验
作者:互联网
// 其实就两行代码就搞定了(加粗显示) @Test public void testHttpsWithApacheHttpClient() throws Exception { SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, TrustAllStrategy.INSTANCE).build(); HttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build(); HttpGet httpGet = new HttpGet("https://127.0.0.1"); HttpResponse httpResponse = httpClient.execute(httpGet); System.out.println(httpResponse.getStatusLine()); System.out.println(EntityUtils.toString(httpResponse.getEntity())); }
标签:HttpGet,custom,build,Https,Apache,httpResponse,HttpClient,out,httpClient 来源: https://www.cnblogs.com/LOVE0612/p/15678170.html