V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
jiobanma
V2EX  ›  Java

请求百度 api,报错: Received fatal alert: handshake_failure

  •  
  •   jiobanma ·
    banmajio · 2022-07-04 16:41:22 +08:00 · 907 次点击
    这是一个创建于 904 天前的主题,其中的信息可能已经有所发展或是发生改变。

    公司一个项目,定时向百度的 api 请求数据,但是总是报错。 jkd:1.8 ; httpclient:4.5.2 ;框架 jfinal 报错信息如下:

    2022-07-04 16:16:15 [DefaultQuartzScheduler_Worker-5] Received fatal alert: handshake_failure
    2022-07-04 16:16:15 [DefaultQuartzScheduler_Worker-5] [
    sun.security.ssl.Alerts.getSSLException(Alerts.java:192), 
    sun.security.ssl.Alerts.getSSLException(Alerts.java:154), 
    sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2020), 
    sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1127), 
    sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367), 
    sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395), 
    sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379), 
    org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:553), 
    org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:412), 
    org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:179), 
    org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:328), 
    org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612), 
    org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447), 
    org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884), 
    org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82), 
    org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107), 
    com.demo.utils.HttpUtils.doPost(HttpUtils.java:51), 
    com.demo.utils.BaiduUtils.callSuccess(BaiduUtils.java:399), 
    com.demo.utils.BaiduUtils.callSuccess(BaiduUtils.java:411), 
    com.demo.utils.BaiduUtils.callSuccess(BaiduUtils.java:411), 
    com.demo.utils.BaiduUtils.getKeyword(BaiduUtils.java:602), 
    com.demo.utils.KeywordUtils.insert(KeywordUtils.java:47), 
    com.demo.plugins.QuartzUploadHeadlineClue.execute(QuartzUploadHeadlineClue.java:42), 
    org.quartz.core.JobRunShell.run(JobRunShell.java:202), 
    org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)]
    2022-07-04 16:16:15 [DefaultQuartzScheduler_Worker-5] javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
    

    百度查到的信息是因为 TLS 的问题,尝试给代码里发送请求前添加

    System.setProperty("https.protocols", "TLSv1.2,TLSv1.1,SSLv3");
    

    发现不起作用。大家又遇到过这个问题的吗?有没有最小成本的解决方案。

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2974 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 13:32 · PVG 21:32 · LAX 05:32 · JFK 08:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.