场景
- 项目A给项目B接口发送数据;
- 项目使用的是hutool的http工具类;
- 本地、测试环境均正常,生产出现了错误,明细:
cn.hutool.http.HttpException: Connection reset
at cn.hutool.http.HttpResponse.init(HttpResponse.java:495)
at cn.hutool.http.HttpResponse.initWithDisconnect(HttpResponse.java:468)
at cn.hutool.http.HttpResponse.<init>(HttpResponse.java:81)
at cn.hutool.http.HttpRequest.doExecute(HttpRequest.java:1130)
at cn.hutool.http.HttpRequest.execute(HttpRequest.java:1012)
at cn.hutool.http.HttpRequest.execute(HttpRequest.java:988)
at com.ylx.review.service.impl.YlxPrePatientServiceImpl.sendYlxStatus(YlxPrePatientServiceImpl.java:142)
at com.ylx.web.controller.review.YlxPrePatientController.editSave(YlxPrePatientController.java:260)
at com.ylx.web.controller.review.YlxPrePatientController$$FastClassBySpringCGLIB$$2d13b7af.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
.......
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:675)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1569)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at cn.hutool.http.HttpConnection.responseCode(HttpConnection.java:470)
at cn.hutool.http.HttpResponse.init(HttpResponse.java:492)
... 104 common frames omitted
我的排查步骤(仅供参考)
- 生产环境接口测试没有问题;
- 在服务器同样可以ping通生产环境,排除白名单问题;
- 使用
timeout()
设置的超时时间,同样也记录了方法调用时间,均没有问题,并不是超时所导致的异常;
我的解决方法
因为对方服务器接口为put
方法,所以我的调用写法为HttpRequest.put(xxxUrl)
;文章来源:https://www.toymoban.com/news/detail-535582.html
这种写法是没什么问题的,但对方服务器的nginx
会把接收到的put
方法重置,最后统一修改为post
请求即可;文章来源地址https://www.toymoban.com/news/detail-535582.html
到了这里,关于cn.hutool.http.HttpException: Connection reset 问题解决的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!