Http_Content-Length

Http Content-Length

如果请求Header设置里Content-Length,则需要和body体长度匹配。否则会出现非预期结果:
1)Content-Length > body length
会等待输入完整body体而阻塞,等待超时后关闭链接。

1
2
3
4
5
6
7
8
9
10
11
12
# curl -X POST -v -H 'Content-Length:1' baidu.com
* Trying 110.242.68.66:80...
* Connected to baidu.com (110.242.68.66) port 80 (#0)
> POST / HTTP/1.1
> Host: baidu.com
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Length:1
>
* Empty reply from server
* Closing connection 0
curl: (52) Empty reply from server

2)Content-Length < body length
会根据Content-Length截断body体。

参考

  1. understand-http-content-length

评论