tags:

views:

107

answers:

1

I have some java-app, and i want to establish a connection to some https Site, how can i do this, using URLConnection? Should i use trust store, when certificate from this site was signed using a valid certificate authority?

+4  A: 

Yes. URLConnection should work. For example,

  URL a = new URL("https://login.yahoo.com");
  conn = a.openConnection();
  InputStream is = conn.getInputStream();

JRE comes with a default trust store with most of the CA certs. As long as the cert is signed by one of them, you don't need to do anything special.

ZZ Coder
But it doesn't works, i recieve such Exception:javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
Le_Coeur
This excpetion i recieve when i have tried to call method connect() from the URLConnection
Le_Coeur
The server is not configured properly. Looks like the port is not configured for SSL. Try the URL in browser to see what happens?
ZZ Coder
Very strange, but now is ok, i didn't correct anything:) Thank u!
Le_Coeur
And one more question, is this connection secure?:)
Le_Coeur
Of course it's secure, that's what the S stands for in https.
ZZ Coder