HttpClient get请求验证URL是否正常

 

项目开发中用org.apache.commons.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.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
	at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:190)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1611)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1574)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1557)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1146)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1123)
	at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:418)
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1041)
	at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
	at sun.net.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 keypair
	at com.sun.net.ssl.internal.ssl.DHCrypt.<init>(DHCrypt.java:106)
	at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverKeyExchange(ClientHandshaker.java:446)
	at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:171)
	at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:516)
	at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:454)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:884)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1112)
	at com.sun.net.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.net.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.,验证后,简直不要太好哦。。非常感谢

网上各路神仙程序员哥哥呀。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值