栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

接口调用遇到Unexpected EOF read on the socket异常问题处理

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

接口调用遇到Unexpected EOF read on the socket异常问题处理

SpringBoot项目在接收参数时,突然出现Unexpected EOF read on the socket异常报错,此时请求还没有进入服务端,初步看起来是客户端的问题。

2022-06-10 11:53:36 [http-nio-10244-exec-3] WARN  o.s.w.s.m.support.DefaultHandlerExceptionResolver.logException 194 --> Resolved [org.springframework.http.converter.HttpMessageNotReadableException: I/O error while reading input message; nested exception is java.io.EOFException: Unexpected EOF read on the socket]
2022-06-10 11:54:06 [http-nio-10244-exec-5] WARN  o.s.w.s.m.support.DefaultHandlerExceptionResolver.logException 194 --> Resolved [org.springframework.http.converter.HttpMessageNotReadableException: I/O error while reading input message; nested exception is java.io.EOFException: Unexpected EOF read on the socket]

       进行Wireshark抓包查看HTTP请求报文,发现只有服务端响应报文,客户端请求报文丢失了。

        请求方式是POST请求参数是String类型,不应该出现接收不到的情况,部署在其他环境上是好的。

    @RequestMapping(value = "/getTest", method = RequestMethod.POST)
    public void getTest(@RequestBody String paramter) {
        log.info(paramter);
    }

        于是我又换了另外一种请求方式,使用request接收,然后通过读取reader的方式获取参数,此时仍然报错,但是查看读取到的数据里面是有参数的,只是参数不完整,无法解析通过JSON转换,此情况表示请求已经接收到了,但是由于某原因导致吧请求放弃停止了。

    @RequestMapping(value = "/getTest", method = RequestMethod.POST)
    public void getTest(HttpServletRequest request) {

        char[] lineChars = new char[1024 * 1024];
        char[] totalChars = new char[1024 * 1024];
        int readLen = 0;
        int totalLen = 0;
        try {
            BufferedReader reader = request.getReader();
            while ((readLen = reader.read(lineChars)) > 0) {
                for (int i = 0; i < readLen; i++) {
                    totalChars[totalLen + i] = lineChars[i];
                }
                totalLen += readLen;
            }
        } catch (Exception e) {
            log.error("数据读取错误{}", e.getMessage());
            return;
        }
}

由于参数有图片Base64数据,怀疑可能数据包过大导致tomcat服务器接不完全导致,于是增加配置参数,让Tomcat服务器不限制大小接收POST接口的数据包,默认为10M。

server.tomcat.max-http-post-size=-1

 修改后替包重启,问题得到了解决。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/961861.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号