0

I am trying to open one htttps website. Url is for ex. https://x.xx.xx.xx/. I have written the blow code.

String url = "https://x.xx.xx.xx/";

URL obj = new URL(url);

HttpURLConnection con = (HttpURLConnection) obj.openConnection();

// optional default is GET con.setRequestMethod("GET");

//add request header con.setRequestProperty("User-Agent", USER_AGENT);

But its throwing the exception "javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative" . I am new to Java. Can anyone help me how to resolve the above issue.

have imported certificate sucessfuly, still getting the exception, can anyone please help me?

Have impor

amiton2006
  • 27
  • 1
  • 3
  • 9
  • Check this post. http://stackoverflow.com/questions/9619030/resolving-javax-net-ssl-sslhandshakeexception-sun-security-validator-validatore – Nirmal Raghavan Sep 27 '13 at 10:02
  • Hi Nirmal, Do I need to ask for certificate from Sever admin or I should create it? – amiton2006 Sep 27 '13 at 10:06
  • You can download it from the browser by visiting that site. This post will be helpful. http://superuser.com/questions/97201/how-to-save-a-remote-server-ssl-certificate-locally-as-a-file – Nirmal Raghavan Sep 27 '13 at 10:10
  • I Have cacerts that comes default with jdk. How shall I import in my java trust store? – amiton2006 Sep 27 '13 at 10:20
  • Have downloaded and imported certificate sucessfully, still getting the above exception. A quick reply would be appriciated. – amiton2006 Sep 28 '13 at 06:45

1 Answers1

0

Two solution : import the server certificate to your java trust store or create a custom unsecured TrustManager trusting all certificats see Java and HTTPS url connection without downloading certificate for an exemple.

Community
  • 1
  • 1
Nemesis
  • 2,180
  • 1
  • 21
  • 20
  • I Have cacerts that comes default with jdk. How shall I import in my java trust store? – amiton2006 Sep 27 '13 at 10:16
  • See http://stackoverflow.com/questions/2893819/telling-java-to-accept-self-signed-ssl-certificate option 1 explain what to do to import a cert in trust store. – Nemesis Sep 27 '13 at 12:29
  • Thank you very much. I tried 2nd option and it worked for me. – amiton2006 Sep 27 '13 at 15:34
  • Hi Nemesis, I by passed the certificate using 2nd option given above but still got ssl certificate error can you tell me how to resolve it? – amiton2006 Sep 27 '13 at 16:41
  • Please post complete stack trace so we can help you (if pb still occurs) and a more complete set of code if possible. – Nemesis Oct 02 '13 at 12:46