架构师

您现在的位置是:首页 > 技术博客 > 编程基础

编程基础

hutool工具包:SSLHandshakeException: Received fatal alert: handshake_failure

架构师小跟班 2020-07-09 编程基础
cn.hutool.core.io.IORuntimeException: SSLHandshakeException: Received fatal alert: handshake_failure问题分析:网上查了下,大部分说法有几种:1、JDK版本问题,升级到1.8就

cn.hutool.core.io.IORuntimeException: SSLHandshakeException: Received fatal alert: handshake_failure

问题分析:

网上查了下,大部分说法有几种:

1、JDK版本问题,升级到1.8就好了。

2、在网络请求前加:System.setProperty("https.protocols", "TLSv1.2,TLSv1.1,SSLv3");

3、修改JVM参数:-Dhttps.protocols=TLSv1.2,TLSv1.1,TLSv1.0,SSLv3,SSLv2Hello

4、旧版本jdk中,jce安全机制的bug,要去oracle官网下载对应的jce包替换jdk中的jce包, 安装路径:%JAVA_HOME%\jre\lib\security。

JDK7:http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html

JDK8:http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

注意:下载需要注册Oracle帐号,网站打开慢不说,注册至少要填写20个左右的必填字段,我特么当时就心态崩了啊卧槽,不过我还是下载下来了,分享给大家。

网盘链接:

链接:https://pan.baidu.com/s/14hGhVCFnmIkuDdYUhfP8eQ 

提取码:5dvl

如果链接失效,可以在我的CSDN博客上下载:

https://download.csdn.net/user/wangxy_job/uploads

你以为到这里就结束了?当然不是!这个方法对我毛用没有。然后我鬼使神差的修改了下访问请求URL,把【https://】去掉了,然后特么的就好使了!!

我的代码:

package com.provy.jiagou.common;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;

/**
 * @author 架构师小跟班
 * @Description: https://www.jiagou1216.com
 * @date 2020/7/9 21:26
 */
public class APIHandler {

    public static String yulu_url = "api.52hyjs.com/api/yulu/api.php?code=json";

    public static void main(String[] args) {
        System.out.println(getYuLu());
    }

    public static String getYuLu(){
//        return HttpRequest.get(yulu_url).setSSLProtocol("SSLv3").execute().body();
        return HttpUtil.get(yulu_url);
    }

}

完整报错:

Exception in thread "main" cn.hutool.core.io.IORuntimeException: SSLHandshakeException: Received fatal alert: handshake_failure

at cn.hutool.http.HttpRequest.send(HttpRequest.java:1098)

at cn.hutool.http.HttpRequest.execute(HttpRequest.java:942)

at cn.hutool.http.HttpRequest.execute(HttpRequest.java:913)

at cn.hutool.http.HttpUtil.get(HttpUtil.java:119)

at cn.hutool.http.HttpUtil.get(HttpUtil.java:107)

at com.provy.jiagou.common.APIHandler.getYuLu(APIHandler.java:19)

at com.provy.jiagou.common.APIHandler.main(APIHandler.java:15)

Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)

at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)

at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2023)

at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1125)

at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)

at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)

at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)

at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)

at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)

at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)

at cn.hutool.http.HttpConnection.connect(HttpConnection.java:377)

at cn.hutool.http.HttpRequest.send(HttpRequest.java:1093)

... 6 more

Process finished with exit code 1



文章评论