HttpClient get请求验证URL是否正常"/>
HttpClient get请求验证URL是否正常
项目开发中用org.apachemons.httpclient.HttpClient get请求验证URL是否正常,使用jdk1.7 80版本 ,大量地址被验证,频繁失败, 日志 报错内容如下:
[WARN ] 2020-12-11 14:27:10 com.szywJobpro.service.impl.ILHMHServiceImpl - java.lang.RuntimeException: Could not generate DH keypair
javax.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypairat com.sun.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:190)at com.sun.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1611)at com.sun.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1574)at com.sun.ssl.internal.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1557)at com.sun.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1146)at com.sun.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1123)at sun.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:418)at sun.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)at sun.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1041)at java.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)at sun.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:318)at com.szywJobpro.service.impl.ILHMHServiceImpl.checkUrl_ZT(ILHMHServiceImpl.java:66)at com.szywJobpro.service.impl.ILHMHServiceImpl.getAll_MHFl(ILHMHServiceImpl.java:132)at com.szywJobpro.service.impl.ILHMHServiceImpl.executeJobStart(ILHMHServiceImpl.java:37)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273)at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:260)at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)at org.quartz.core.JobRunShell.run(JobRunShell.java:203)at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
Caused by: java.lang.RuntimeException: Could not generate DH keypairat com.sun.ssl.internal.ssl.DHCrypt.<init>(DHCrypt.java:106)at com.sun.ssl.internal.ssl.ClientHandshaker.serverKeyExchange(ClientHandshaker.java:446)at com.sun.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:171)at com.sun.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:516)at com.sun.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:454)at com.sun.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:884)at com.sun.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1112)at com.sun.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1139)... 18 more
Caused by: java.security.InvalidAlgorithmParameterException: Prime size must be multiple of 64, and can only range from 512 to 1024 (inclusive)at com.sun.crypto.provider.DHKeyPairGenerator.initialize(DashoA13*..)at java.security.KeyPairGenerator$Delegate.initialize(KeyPairGenerator.java:627)at com.sun.ssl.internal.ssl.DHCrypt.<init>(DHCrypt.java:100)... 25 more
借鉴网上很多大佬的出现问题的解说,
1、jre的加密策略原因,导致SSL请求还没发出去,客户端就自己断了连接。
2、说是TLS版本的问题,jdk1.7默认的TLS版本是1.0,将TLS版本改成1.1或者1.2就行。
解决问题有如下:
1、代码增加:System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");验证了,无效。
2、更换jdk1.7 131版本及以上,TLS1.2 For JRE 1.7.0_131-b31 in Oracle site : TLSv1.2 and TLSv1.1 are now enabled by default on the TLS client end-points. This is similar behavior to what already happens in JDK 8 releases.,验证后,简直不要太好哦。。非常感谢
网上各路神仙程序员哥哥呀。
更多推荐
HttpClient get请求验证URL是否正常
发布评论