Java平台库支持https吗

发布于 2024-08-31 04:32:12 字数 40 浏览 3 评论 0原文

我需要做的就是通过 https 连接。我必须为此使用公共客户端吗?

All I need to to do is to connect via https. Must I use commons client for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海夜未眠 2024-09-07 04:32:12

不,您不必这样做,您可以使用常规的 URLConnection。像这样的事情:

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();
    }    
}

如果您要连接的站点使用未经知名 CA 签名的证书或自签名证书,则可能需要做更多的工作。但这是另一个故事了。

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.

一生独一 2024-09-07 04:32:12

是的。只需使用 URL 类并指定 HTTPS url。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文