dromara / hutool

🍬A set of tools that keep Java sweet.
https://hutool.cn
Other
29.25k stars 7.54k forks source link

https请求 Connection reset,每次尝试都能复现 #3781

Closed 1228181394 closed 3 weeks ago

1228181394 commented 3 weeks ago

版本情况

JDK版本: java version "1.8.0_333" hutool版本: 5.8.21

问题描述(包括截图)

  1. 复现代码
 String httpResult = HttpRequest.post(report_data_url).header("Access-Token",js.getString("accessToken"))
                                .form(parameter).timeout(30000).execute().body();
  1. 堆栈信息 Caused by: cn.hutool.core.io.IORuntimeException: SocketException: Connection reset at cn.hutool.http.HttpRequest.send(HttpRequest.java:1341) at cn.hutool.http.HttpRequest.doExecute(HttpRequest.java:1189) at cn.hutool.http.HttpRequest.execute(HttpRequest.java:1052) at cn.hutool.http.HttpRequest.execute(HttpRequest.java:1028) at com.timer.service.lambda$saveCreativeLevelOfflineReportData$0(java:64) at java.util.ArrayList$Itr.forEachRemaining(ArrayList.java:891) at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580) at com.timer.service.saveCreativeLevelOfflineReportData(java:56) at com.timer.service.$$FastClassBySpringCGLIB$$e5fd2083.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:59) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) at com.timer.service.ReportDataService$$EnhancerBySpringCGLIB$$ab61c391.saveCreativeLevelOfflineReportData() at com.timer.controller.XiaoHongShuReportDataController.saveCreativeLevelOfflineReportData(XiaoHongShuReportDataController.java:29) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:269) at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:257) ... 3 more Caused by: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:210) at java.net.SocketInputStream.read(SocketInputStream.java:141) at sun.security.ssl.InputRecord.readFully(InputRecord.java:465) at sun.security.ssl.InputRecord.read(InputRecord.java:503) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387) at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1291) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250) at cn.hutool.http.HttpConnection.getOutputStream(HttpConnection.java:458) at cn.hutool.http.HttpRequest.sendFormUrlEncoded(HttpRequest.java:1358) at cn.hutool.http.HttpRequest.send(HttpRequest.java:1333) ... 36 more
  2. 测试涉及到的文件(注意脱密)

比如报错的Excel文件,有问题的图片等。

looly commented 3 weeks ago

应该是服务端拒绝了你的连接,检查:

  1. 服务器是否忙碌
  2. 你是否够被拉黑(使用HttpClient等库做个验证)
  3. 对于特定头是否有检查