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
2009-09-09 09:38:08
But it doesn't works, i recieve such Exception:javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
Le_Coeur
2009-09-09 10:50:41
This excpetion i recieve when i have tried to call method connect() from the URLConnection
Le_Coeur
2009-09-09 10:57:32
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
2009-09-09 11:07:01
Very strange, but now is ok, i didn't correct anything:) Thank u!
Le_Coeur
2009-09-09 11:09:11
And one more question, is this connection secure?:)
Le_Coeur
2009-09-09 11:19:04
Of course it's secure, that's what the S stands for in https.
ZZ Coder
2009-09-09 12:02:35