// 其实就两行代码就搞定了(加粗显示) @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())); }