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

本文针对第三方接口调用时出现的SSLHandshakeException问题,提供了详细的解决方案,包括检查JDK版本和通过HTTPSURLConnection处理HTTPS请求的具体代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

解决方案:

1.网上查资料大部分是说jdk版本问题:https://blog.youkuaiyun.com/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();
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值