ERR_INVALID_CHUNKED_ENCODING error or curl: (18) transfer closed with outstanding read data remaining error Solution

ERR_INVALID_CHUNKED_ENCODING错误

curl: (18) transfer closed with outstanding read data remaining错误

Failed to load response data错误

Final Solution

Symptoms:

The front console error: ERR_INVALID_CHUNKED_ENCODING error process

 

Debug mode in response to the front end of the blank can be seen, show: Failed to load response data

 

Request response header contains Transfer-Encoding: chunked, and returns to the normal 200

Log in to view the log server returns the correct data.

what? ? ? ?

Return to normal back-end, front-end display 200 state, but it is an error, where the data go?

Correct! Where's the data? Description back-end to front-end data, the data is lost.

Why lose it, by printing response.getBufferSize (); get 8192 byte, which is about 8k

Since the interface has returned more data than 8k, which is obviously not enough, all the settings response.setBufferSize (1024000), is set to be greater than 1m of the cache.

Here the problem is solved.

Continue to analyze:

problem causes:

Due to the use of Transfer-Encoding: chunked instead of Content-length ,

-Length the Content : HTTP message transfer length is used to describe an entity, the client (server) can be determined whether data has been received, the browser creates a corresponding page buffer size based on the size of the response data based on this value.

Transfer-Encoding:chunk模式传输 数据。即服务器一边产生数据,一边发给客户端,服务器就需要使用”Transfer-Encoding: chunked”这样的方式来代替Content-Length。由于这种模式浏览器不知道服务器相应数据的大小,并且服务器默认配置的缓存大小是:8k,所以如果超过这个响应数据的大小,浏览器就会有这种错误。

问题解决3种方式(后三种可以尝试,第一种亲测成功):

1、Nginx的目录权限:

            当输出代理文件大小超过配置proxy_temp_file_write_size时候,nginx会将文件写入到临时目录下。如果没有权限,chrom就会直接failed而不输出东西。

解决方法:

chown -R www:www /var/lib/nginx

其中www替换为自己实际项目中配置的ngxin运行用户,即root用户。

这个问题回顾是安装nginx的时候,直接yum install。在配置web的时候,忘了改/var/lib/nginx的目录权限(默认是nobody)。默认是nginx:nginx的组权限,平时不用这个账号启动。所以在碰到输出较大的body的时候,就触发了这个et::ERR_INCOMPLETE_CHUNKED_ENCODING错误。

(可以参考:https://blog.csdn.net/qq_35624642/article/details/79104353

2、更改Nginx的配置

加大Nginx的buffer可以临时解决这个问题。如以下Nginx配置:
http{
................................
    proxy_buffer_size 128k;
    proxy_buffers   32 128k;
    proxy_busy_buffers_size 128k;
    .............................
}

3、处理报错的响应接口(局部处理,只是解决这一个接口)在Controller层方法上注明response。

@PostMapping("/test")
public R<String> test(HttpServletResponse response, @RequestBody IDDTO id) {
   response.setBufferSize(1024000);//设置缓存大小约1M即可,默认是8192byte,也就是8k
}

4、配置tomcat的属性(全局处理,应用所有的接口)(参考:https://blog.csdn.net/lowkeysk/article/details/8286485)

微服务配置:

server:

      max-http-header-size: 1024000   // HTTP请求、响应头信息的最大大小

配置tomcat配置属性 maxHttpHeaderSize=1024000

 

   
 

Guess you like

Origin blog.csdn.net/m0_37668842/article/details/89138733