报错 org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body
org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body 的解决办法
文章共390字 · 阅读需要大约2分钟
一键AI生成摘要,助你高效阅读
问答
·
文章目录
报错 org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body 的解决办法
报错场景:在使用httpclient下载大文件时候报错。
错误分析:
-
- 请求链接提前关闭导致拿到数据包和期待数据包不一致。
-
- http请求不稳定,文件过大导致数据包丢失,即下载大的数据包时丢失了数据。
解决办法:
文件过大导致数据包丢失,可以采用分片下载、断点续传的方式,把文件分块进行下载。具体实现方法是在请求头中加以下代码:
Header header = new BasicHeader("Range", "bytes=" + startIndex + "-" + endIndex);
更多推荐
已为社区贡献2条内容
所有评论(0)