HTTP Status Code 411 = “Length Required”
The server refuses to process the request because the Content-Length header is missing.
Why this happens
Some servers require the client to specify the exact size of the request body before accepting the request.
If the request does not include:
http id=”m7q2we”
Content-Length
the server may return:
http id=”v4k8ra”
HTTP/1.1 411 Length Required
Example
Problematic request
http id=”n3p1xd”
POST /upload HTTP/1.1
Content-Type: application/json
Missing:
http id=”u8w5kc”
Content-Length: 123
Correct request
http id=”g7q2mv”
POST /upload HTTP/1.1
Content-Type: application/json
Content-Length: 27
Common causes
- Improper HTTP client configuration
- Custom socket requests
- Proxy/load balancer restrictions
- Missing headers in APIs
- Streaming/chunked request issues
Fixes
1. Add Content-Length header
JavaScript fetch
Usually automatic:
js id=”r5k9zn”
fetch(‘/api’, {
method: ‘POST’,
body: JSON.stringify(data)
});
2. Node.js example
js id=”t2p4xe”
const body = JSON.stringify(data);
fetch(url, {
method: ‘POST’,
headers: {
‘Content-Length’: body.length
},
body
});
3. PHP cURL
cURL usually sets it automatically:
php id=”q6m3yt”
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
4. Python requests
Automatically handled:
python id=”w9k1vc”
requests.post(url, json=data)
Special case: chunked transfer
If using:
http id=”p4q7ra”
Transfer-Encoding: chunked
some servers may not require Content-Length.
Difference between 411 and 413
| Code | Meaning |
| — | – |
| 411 | Missing Content-Length |
| 413 | Payload too large |
Related HTTP status codes
| Code | Meaning |
| — | – |
| 400 | Bad Request |
| 411 | Length Required |
| 412 | Precondition Failed |
| 413 | Payload Too Large |
| 415 | Unsupported Media Type |