http长连接Transfer-Encoding: chunked 和 Content-Length

一个对外接口说长链接时报文少了 content-length导致无法读取正文,查资料content-length和Transfer-Encoding是只会出现一个的

为什么以前是content-length现在却显示了Transfer-Encoding,而且正文头尾有用特定符号标识开始结束(1f8d 和 0)

使用curl的-v参数查看http报文调试,开始以为nginx有什么特殊配置,直播调试两台httpd机器也返回了不同的值。

 

curl -v -H "HOST:test.com"   http://192.168.1.250:8082/api/test.html
* About to connect() to 192.168.1.250 port 8082 (#0)
*   Trying 192.168.1.250... connected
* Connected to 192.168.1.250 (192.168.1.250) port 8082 (#0)
> GET /api/test.html HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.2.3 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Accept: */*
> HOST:test.com
< HTTP/1.1 200 OK
< Date: Fri, 26 Jan 2018 11:03:47 GMT
< Server: Apache/2.2.22 (Unix)
< Transfer-Encoding: chunked
< Content-Type: text/html;charset=utf-8
 
 
 curl -v -H "HOST:dev.com"   http://172.16.134.152:8082/api/test.html
* About to connect() to 172.16.134.152 port 8082 (#0)
*   Trying 172.16.134.152... connected
* Connected to 172.16.134.152 (172.16.134.152) port 8082 (#0)
> GET /api/test.html HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Accept: */*
> HOST:dev.com
< HTTP/1.1 200 OK
< Date: Fri, 26 Jan 2018 11:00:58 GMT
< Server: Apache/2.4.25 (Unix)
< Content-Length: 6336
< Content-Type: text/html;charset=utf-8
 
进一步在输出chunked的机器做代码调试,发现输出内容短了就会显示成Content-Length 内容长了就会显示成Transfer-Encoding: chunked 问题排查完毕
那么使用方可能要根据头部来实现两种方法来读取正文内容了

上一篇: 解决kubectl exec terminal 部分命令无法使用问题   下一篇: 没有了

提交疑问

回顶部