0

I want to access a secure URL using HttpsURLConnection and am having trouble reading the content back.

I am using the trustmanager example given here and have added the following code to access the page content:

HttpsURLConnection urlc = (HttpsURLConnection) new URL( <url> ).openConnection();
BufferedReader readIn= new BufferedReader(new InputStreamReader(urlc.getInputStream()));
String eachLine;
String inputLine = "";
while ((eachLine = readIn.readLine()) != null) {
   inputLine += eachLine;
}

The trouble is, I keep getting the error:

java.security.cert.CertificateException: No subject alternative names present

Any ideas why? Thanks

EDIT
I forgot to mention, I am doing this using Spring and trying to call a servlet from another class.

Jon
  • 3,174
  • 11
  • 39
  • 57
  • 1
    http://stackoverflow.com/questions/10258101/sslhandshakeexception-no-subject-alternative-names-present – jdevelop Sep 04 '12 at 11:19
  • Thanks, I saw that but I couldn't figure out how to integrate it into my project. I was hoping there would be a simpler solution that didn't involve generating keys etc. – Jon Sep 04 '12 at 11:23
  • This might help http://humandoing.net/blog/2006/03/06/java-ssl-trust-manager/ – Ruwantha Sep 04 '12 at 11:32
  • Thanks, but that's the link I posted in my question! =P It only takes you as far as connecting, which seems OK. Its actually getting the page content back which is a little tricky... – Jon Sep 04 '12 at 11:34
  • @RJ45, please don't encourage using this trust manager: it disables certificate verification and makes the connection vulnerable to MITM attacks. – Bruno Sep 04 '12 at 12:56
  • @Jon, are you in control of that server? – Bruno Sep 04 '12 at 12:57
  • Yes, I am testing the project locally at the moment but I am unsure how to create certificates or pass login details so that I can access the secured page. Do you know the most straight-forward way of doing this? – Jon Sep 04 '12 at 13:35

0 Answers0