开发者

Do the Java platform libraries support https

开发者 https://www.devze.com 2022-12-28 16:27 出处:网络
All I need to to do is to connect via https. Must I u开发者_StackOverflowse commons client for this?No, you don\'t have to, you can use a regular URLConnection. Something like this:

All I need to to do is to connect via https. Must I u开发者_StackOverflowse commons client for this?


No, you don't have to, you can use a regular URLConnection. Something like this:

public class URLConnectionReader {

    public static void main(String[] args) throws Exception {
        URL url = new URL("https://jax-ws.dev.java.net/");
        URLConnection uc = url.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
                                uc.getInputStream()));
        String inputLine;

        while ((inputLine = in.readLine()) != null) {
            System.out.println(inputLine);
        }
        in.close();
    }    
}

This may require a bit more work if the site you're connecting to uses a certificate that has not been signed by a well known CA or a self-signed certificate. But this is another story.


Yes. Just use the URL class and specify an HTTPS url.

0

精彩评论

暂无评论...
验证码 换一张
取 消