公司一个项目,定时向百度的 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");
发现不起作用。大家又遇到过这个问题的吗?有没有最小成本的解决方案。