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 answer but could not implement it.
java.security.cert.CertificateException: No subject alternative DNS name matching www.example.com found.
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();