Connect to https Site(Server)

2019-05-26 18:00发布

问题:

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?

回答1:

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.



标签: java ssl https