小编Joe*_*oth的帖子

在 JAVA 中发出 HTTPS 请求并打开 SSL 套接字

我正在尝试构建一个登录页面。为此,我想打开 SSL 套接字并发出 HTTPS 请求,但我在该行中收到未知主机异常

SSLSocket skt = (SSLSocket)sslsf.createSocket("https://31.21.18.222/room_info/x.txt" , 443);
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我我做错了什么吗?另外,我已经关闭了主机验证,因为我的程序中不需要它。

`public void clickLogin() throws IOException, CertificateException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
            
                                       
            URL url = new URL ("https://31.21.18.222/room_info/x.txt");
            HttpsURLConnection connection = null;
            KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            keyStore.load(null);        //Make an empty store
            InputStream fis = new FileInputStream("C:/Documents and Settings/user/Desktop/PK/localhost.crt"); 
            BufferedInputStream bis = new BufferedInputStream(fis);
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            while (bis.available() > 0) {
                java.security.cert.Certificate cert = cf.generateCertificate(bis);
                keyStore.setCertificateEntry("localhost", cert);
            }
            
            // write code for turning off client verification
            TrustManagerFactory tmf = …
Run Code Online (Sandbox Code Playgroud)

ssl https javafx

4
推荐指数
1
解决办法
4192
查看次数

标签 统计

https ×1

javafx ×1

ssl ×1