<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.13</version> </dependency>
// 其实就两行代码就搞定了(加粗显示) @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:8443"); HttpResponse httpResponse = httpClient.execute(httpGet); System.out.println(httpResponse.getStatusLine()); System.out.println(EntityUtils.toString(httpResponse.getEntity())); }