title: How to bypass CertificateException by Java?
body: <p>I am trying to send a request to a server but it runs into following error, as I know should create a certificate but not sure how to do it. I've found this <a href="https://stackoverflow.com/questions/859111/how-do-i-accept-a-self-signed-certificate-with-a-java-httpsurlconnection/859271#859271">answer</a> but could not implement it.</p>
  
  <pre><code>java.security.cert.CertificateException: No subject alternative DNS name matching www.example.com found.
  </code></pre>
  
  <p>Code </p>
  
  <pre><code>        URL url = new URL("https://www.example.com:1897/services/myservice");
  
          HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
  
          con.setRequestMethod("POST");
          con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
          con.setDoOutput(true);
          con.setDoInput(true);
  
          OutputStream os = con.getOutputStream();
          m.marshal(auth, os);
          m.marshal(auth, System.out);
  
          os.flush();
          con.getResponseCode();
  </code></pre>