公司一个项目,定时向百度的 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");
发现不起作用。大家又遇到过这个问题的吗?有没有最小成本的解决方案。
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.