How to bypass ssl certificate checking in java

前端 未结 4 1876
忘掉有多难
忘掉有多难 2020-11-30 05:50

I want access a SOAP webservice url having https hosted in a remote vm. I am getting an exception while accessing it using HttpURLConnection.

Here\'s my code:

<
4条回答
  •  星月不相逢
    2020-11-30 06:42

    Try with Apache HTTP client, this works for me.

    SSLContextBuilder builder = new SSLContextBuilder();
    builder.loadTrustMaterial(null, new TrustStrategy() {
         public boolean isTrusted(final X509Certificate[] chain, String authType) throws CertificateException {
              return true;
         }
    });
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
    
    CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
    
    // GET or POST request with the client
    ...
    

提交回复
热议问题