title: How to make HTTPS SOAP request bypassing SSL certificate in Java
body: <p>I am trying to make a HTTPS request using <code>Ksoap</code> in a Java console application. I need to make a SOAP request to the following local URL on my LAN Network:</p>
  <p><code>https://192.168.0.43:7002/Examples/TestService?WSDL</code></p>
  <p>Since it is a HTTPS request, i need to bypass the certificate and hit the webservice. I am using the webservice in testing environment only.</p>
  <p>Here is my java code that uses ksoap to send the SOAP request.</p>
  <pre><code> public class ConnectHttps {
      public static void main(String[] args) throws Exception {
    /*
   *  fix for
   *    Exception in thread &quot;main&quot; javax.net.ssl.SSLHandshakeException:
   *       sun.security.validator.ValidatorException:
   *           PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:
   *               unable to find valid certification path to requested target
   */
  TrustManager[] trustAllCerts = new TrustManager[] {
     new X509TrustManager() {
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
          return null;
        }
  
        public void checkClientTrusted(X509Certificate[] certs, String authType) {  }
  
        public void checkServerTrusted(X509Certificate[] certs, String authType) {  }
  
     }
  };
  
  SSLContext sc = SSLContext.getInstance(&quot;SSL&quot;);
  sc.init(null, trustAllCerts, new java.security.SecureRandom());
  HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
  
  // Create all-trusting host name verifier
  HostnameVerifier allHostsValid = new HostnameVerifier() {
      public boolean verify(String hostname, SSLSession session) {
        return true;
      }
  };
  // Install the all-trusting host verifier
  HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
  /*
   * end of the fix
   */
    
   //send SOAP Request
     URL url = new URL(&quot;https://192.168.0.43:7002/Examples/TestService?WSDL&quot;);
  
      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
      envelope.setOutputSoapObject(request); 
      
  
      //HttpsTransportSE  androidHttpTransport= new KeepAliveHttpsTransportSE(&quot;https://192.168.0.43&quot;, 7002, &quot;TestService&quot;, 9000);
  
      try{
  
          HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
  
          androidHttpTransport.call(SOAP_ACTION, envelope);   
  
          SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
  
          if (envelope.bodyIn instanceof SoapFault) {
              String str= ((SoapFault) envelope.bodyIn).faultstring;
  
              System.out.println(&quot;&quot; +str);
  
          } else {
              SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
              System.out.println(&quot;WS&quot;+ &quot;&quot;+ String.valueOf(resultsRequestSOAP));
          }
      }catch(Exception ex)
      {
          System.out.println(&quot;Error:&quot; +ex.getMessage());
          ex.printStackTrace();
  
      }*/
  
  
  
    }
  }
  </code></pre>
  <p>Note: I have modified the code as per mentioned in this <a href="https://stackoverflow.com/questions/3440062/ksoap-2-android-with-https">link</a></p>
  <p>However, whenever i run the code, I am getting a <code>security policy error with code 1000</code>. The error occurs at line <code>androidHttpTransport.call(SOAP_ACTION, envelope);</code> resulting in a <code>SoapFault</code></p>
  <p>How should I make the HTTPS call using Ksoap</p>