javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

项目中遇到提供给第三方的接口那边调用调不通出现:javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake,但浏览器访问正常。

解决方案:

1.网上查资料大部分是说jdk版本问题:https://blog.csdn.net/kevin_mails/article/details/82143490,我本地jdk1.8.0_162确实测试类跑也正常,但同事jdk1.8.0_0xx却出现上述异常。

2.后面测试代码方案主要是htts的url强转HttpsURLConnection处理。

URL url = new URL(urlPath);
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        InputStream inputStream;
        String encoding;
        if (urlPath.startsWith("https")) {
            HttpsURLConnection https = (HttpsURLConnection) urlConnection;
            // 设置doOutput属性为true表示将使用此urlConnection写入数据
            https.setDoOutput(true);
            // 定义待写入数据的内容类型,我们设置为application/x-www-form-urlencoded类型
            https.setRequestProperty("Content-Type", "application/json");
            https.setConnectTimeout(10000);
            https.setReadTimeout(10000);
            https.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(https.getInputStream()));
            String lines;
            while ((lines = reader.readLine()) != null) {
                System.out.println(lines);
            }
            reader.close();
            https.disconnect();
        }

 

你可能感兴趣的:(bug)