org.apache.http.ConnectionClosedException Premature end of Content-Length delimited message body
最近生产环境报了这个系统异常:
org.apache.http.ConnectionClosedException Premature end of Content-Length delimited message body (expected 107915; received 40177)
查看日志后发现是下载文件的时候出错。
具体的代码如下:
StringEntity entityParams = new StringEntity(requestXml, "utf-8");HttpPost httpPost = new HttpPost(serverUrl);httpPost.setEntity(entityParams);httpPost.setHeader("Content-Type", "text/xml;charset=ISO-8859-1");client = HttpClients.createDefault();// 向威富通发送对账请求,并获取结果response = client.execute(httpPost);
在向威富通发送请求的时候有下载文件的操作,出现了该问题。
起初是怀疑http的超时时间过短导致了该问题,由于默认的时间是30s,并且我们接收到的没有到总的1/2(4w/10w),所以将超时时间设置为了120s,修改后的代码如下:
StringEntity entityParams = new StringEntity(requestXml, "utf-8");HttpPost httpPost = new HttpPost(serverUrl);RequestConfig config = RequestConfig.custom().setSocketTimeout(120000).setConnectTimeout(120000).build();httpPost.setConfig(config);httpPost.setEntity(entityParams);httpPost.setHeader("Content-Type", "text/xml;charset=ISO-8859-1");client = HttpClients.createDefault();// 向威富通发送对账请求,并获取结果response = client.execute(httpPost);
但是在重新执行该代码的时候还是报同样的问题,修改tomcat和nginx的超时时间都没有解决该问题。另外有一些细节需要注意:
1.多次下载同一个文件时的received都是40177。
2.第二天的文件更大,达到了15w,此时的received仍然是40177。
所以有很大的理由来怀疑是Nginx的缓冲区大小导致了该问题。
在Nginx的配置文件中(http内server外)加入以下代码:
sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;#以上为系统自带 以下为自己添加proxy_buffering on;proxy_buffer_size 64k;proxy_buffers 8 32k;proxy_temp_path proxy_temp 1 2;proxy_request_buffreing on;proxy_read_timeout 300s;proxy_send_timout 300s;
然后重新执行这段代码得以解决该问题。
参考文章:记一个 httpclient 神坑 - 掘金 (juejin.cn)
org.apache.http.ConnectionClosedException Premature end of Content-Length delimited message body相关推荐
- Java报错解决:org.apache.http.ConnectionClosedException: Premature end of chunk coded message body: closi
再跑爬虫程序的时候突然遇到了如下报错: org.apache.http.ConnectionClosedException: Premature end of chunk coded message ...
- org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body
2019独角兽企业重金招聘Python工程师标准>>> 发送http请求给后端服务,在数据量大的时候报错: org.apache.http.ConnectionClosedExcep ...
- Jmeter压测报错:org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited mess
Jmeter压测遇到报错:org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited me ...
- The maximum string content length quota (8192) has been exceeded while reading XML data
原文: The maximum string content length quota (8192) has been exceeded while reading XML data 问题场景:在我们 ...
- Premature end of Content-Length delimited message body解决方案
[辰兮要努力]:hello你好我是辰兮,很高兴你能来阅读,昵称是希望自己能不断精进,向着优秀程序员前行! 博客来源于项目以及编程中遇到的问题总结,偶尔会有读书分享,我会陆续更新Java前端.后台.数据 ...
- Posted content length of 26789546 exceeds limit of 10485760
原来jfinal中默认上传为10M(10*1024*1024),故超过10M会报错 注:https://blog.csdn.net/weixin_43706875/article/details/10 ...
- Premature end of Content-Length delimited message body 报错原因
我在读取es数据的时候报这个错. 原因是:我配置了4个logstash实例读取同一个es的数据,当我关掉这四个logstash后es读取数据恢复正常
- MAC | svn: E175002: DAV request failed: 411 Content length required.
今天在做svn compare的时候发现的这个问题 ! 网上有人说: 这可能是因为您的后端是较旧的svn版本. 在.subversion / servers文件中添加如下代码 [global] htt ...
- 服务器架设笔记——使用Apache插件解析简单请求
一般来说,对于一个请求,服务器都会对其进行解析,以确定请求的合法性以及行进的路径.于是本节将讲解如何获取请求的数据.(转载请指明出于breaksoftware的csdn博客) 我们使用<服务器架 ...
最新文章
- 初识vue 2.0(2):路由与组件
- win10 家庭版 CredSSP加密Oracle修正 设置方法
- ui5里周期性检查window size大小的变化
- Oracle的分页实现
- spring mvc学习(2):spring jar包下载
- 设计模式--6大原则--迪米特法则
- activeperl安装不成功_SWOOLE进阶-00环境安装
- python 时分秒相加大于24h_在python中,将24小时加到负时间差上
- java微信支付详解_java微信支付接入流程详解
- select2控件+拼音智能检索
- Python code on Sliced Inverse Regression ( SIR ) and Sliced Average Variance Estimates ( SAVE )
- imToken的创始人何斌:让区块链泛式革命在社区蔓延开来
- idea open操作打开文件夹无反应
- Modbus 超时时间设置
- luogu2657-Windy数题解--数位DP
- SSH Keylogger密码抓取
- 指纹识别软件:EHole(棱洞)使用记录
- MVC与模板概念的理解
- html5页面文件打包,Webpack入门(四)——HTML打包
- C++ 读文件某一行(特定行)数据