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()));
}

 

上一篇:java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.widget.RadioGroup.set


下一篇:vue3通过app.config进行配置