411
Client Error
411 Length Required: Missing ContentโLength
โฆ The Golden Answer: The 411 Length Required status code means the server refuses to accept the request without a valid
Content-Length header. This header tells the server exactly how many bytes the request body contains. The client must include the Content-Length header with the correct size of the request body in bytes. This error is uncommon with modern HTTP libraries, but can occur with older clients or when using raw HTTP sockets.
Why 411 Happens
- Missing Content-Length โ the client did not include the header.
- Incorrect Content-Length โ the value does not match the actual body size (server may return 411 or 400).
- Server requires Content-Length โ some older or stricter servers require this header even when chunked transfer encoding could be used.
- Proxy or middleware strips the header โ an intermediate system may remove the header, causing the origin server to see it as missing.
Example: 411 Response
When a client sends a POST request with no Content-Length header:
POST /api/data HTTP/1.1
Host: example.com
Content-Type: application/json
{"key": "value"}
HTTP/1.1 411 Length Required
Content-Type: text/html
Content-Length: 0
How to Fix 411
- If you're a client developer: Ensure your HTTP library automatically adds the
Content-Lengthheader. Most libraries (e.g., fetch, axios, requests) do this automatically. If you're using raw sockets, calculate the body length and add the header manually. - If you're a server administrator: Consider relaxing the requirement for
Content-Lengthand supportingTransfer-Encoding: chunkedinstead. Many modern servers support both. - If you're an endโuser: This error is almost always due to a bug in the application or API client. Contact the developer.
Content-Length vs. Transfer-Encoding
| Header | Purpose | Use Case |
|---|---|---|
| Content-Length | Specifies the exact size of the request body in bytes. | When the entire body is known before sending (e.g., small payloads). |
| Transfer-Encoding: chunked | Allows sending the body in chunks, without knowing the total size upfront. | For large or dynamically generated content (e.g., file uploads, streaming). |
Some older servers may reject chunked encoding and require Content-Length. However, most modern servers support both.
When 411 Is Rarely Seen
- Most modern HTTP libraries (Python requests, JavaScript fetch, Java HttpClient) handle this automatically.
- Servers like Nginx and Apache do not require Content-Length for chunked requests.
- You are more likely to see 411 when working with custom or legacy clients.
Frequently Asked Questions
Is 411 a client error or a server error?
It's a client error (4xx). The client failed to include the required Content-Length header. However, the server could support chunked transfer encoding to avoid this error.
Can I use both Content-Length and Transfer-Encoding?
No, you should not send both. If you send Transfer-Encoding: chunked, the Content-Length header is ignored (or should not be sent).
Why would a server require Content-Length?
Some older servers or strict security configurations may require Content-Length to prevent certain types of attacks. However, it's generally better to support chunked encoding for flexibility.