Content-Length
用以指定 Body 的体积。响应头中的 Content-Length
指定 Response Body
的体积,请求头中的 Content-Length
指定 Request Body
的体积。
通过 Content-Length
,HTTP 客户端/服务器端将会根据该头部计算出 Body 的大小。
请求头中的 Content-Length
在 fetch
等 HTTP 客户端中将会根据 Request Body
的体积自动计算出 Content-Length
,所以,Content-Length
一般不需要手动指定。
但是,如果 Content-Length
指定体积过小,将无法传输完整的 Body。通过 Apifox Echo 示例如下。
# 指定 3,则只能接收到 a=3,body 将被截断
$ curl -X POST https://echo.apifox.com/post -d "a=3000" -H "content-length: 3"
{"args": {}, "data": "", "files": {}, "form": {"a": "3"}, "headers": {"Accept": "*/*", "Content-Length": "3", "Content-Type": "application/x-