411 Length Required: Add a Content-Length
411 Length Required means the server rejected a request with no Content-Length. Buffer the body, set the length, resend. Free instant check, no sign-up.
Check your domain for this issue now
Free, no sign-up. Runs the exact check this guide describes and shows what to fix.
Problem
You send a POST or PUT and the server bounces it with 411 Length Required before doing any work. The body is right there in your request — but the server won’t touch it. It isn’t objecting to what you sent; it’s objecting to what you didn’t declare: the size of the body, up front, as a Content-Length header.
Symptoms
- A
POST/PUT/PATCHreturns 411 immediately, with no application-level error. - The same call works from
curlor Postman but fails from your code (or vice versa). - It happens on streamed or chunked uploads — piping a file, a stream, or a generator into the request body.
- Some clients hit it on an empty-body POST (a form submit or webhook with nothing to send).
- The failing requests carry
Transfer-Encoding: chunkedinstead ofContent-Length.
What This Error Actually Means
HTTP/1.1 gives you two ways to frame a request body. You can send Content-Length: 4096 and then exactly 4096 bytes — a fixed, known size. Or you can send Transfer-Encoding: chunked and stream the body in pieces, terminated by a zero-length chunk, without ever committing to a total. The chunked form exists precisely so you can start sending before you know how much there’ll be.
RFC 9110 §15.5.12 defines 411 as the server’s refusal to take the second option: it “refuses to accept the request without a defined Content-Length.” The server wants to know the size before it reads a byte — usually so it can pre-allocate a buffer, enforce a maximum request size, or hand the body to something (a legacy handler, a strict WAF, a storage API) that can’t cope with a stream of unknown length.
The word that matters is defined. This isn’t about a body being empty or malformed. It’s about the server declining to accept a body whose length it can’t see in advance. The RFC is equally explicit about the cure: the client “MAY repeat the request if it adds a valid Content-Length header field.” So a 411 is not a dead end — it’s a specific instruction. Buffer the thing, count the bytes, tell the server the number.
Top 3 Causes
- Your HTTP client is streaming the body as chunked. This is the common one. Hand many HTTP libraries a file object, a stream, or a generator as the request body and they’ll default to
Transfer-Encoding: chunkedrather than reading the whole thing to compute a length. Against a server that requiresContent-Length, every one of those uploads 411s. The tell: it works when you pass a fixed string or byte buffer and fails when you pass a stream. - An empty-body POST with no length header. Some clients omit
Content-Lengthentirely when there’s no body to send — a bare form submission, a webhook ping, aPOSTused as a trigger. A strict server reads “no Content-Length, no chunked encoding” as “I can’t tell where this request’s body begins or ends” and returns 411. The fix is a single header:Content-Length: 0. - A strict server or middlebox that rejects chunked request bodies. Older IIS setups, some Java servlet containers, certain object-storage endpoints, and hardened WAFs refuse chunked requests on purpose — they want a length so they can enforce limits before buffering. Your client is behaving reasonably; the server has simply opted out of the streaming path, and it’s telling you so with 411.
Diagnose with DechoNet
- HTTP Check confirms the response is genuinely a 411 from the origin and not a 400 or 413 you’ve misread — the three get conflated constantly, and they have opposite fixes. Seeing the exact status code and the response headers is the first step before you touch your client.
- The check shows the response headers, so you can see whether a proxy, CDN, or WAF is in the path. A 411 that appears only when a request transits a particular edge points at a middlebox policy, not your origin — worth knowing before you rewrite your upload code.
Resolution Checklist
- Confirm it’s really 411, not 413 (too large) or 431 (headers too big). The fix diverges completely: 411 means add a length; 413 means shrink the body; 431 means trim headers.
- Send a
Content-Lengthinstead of chunked. In your HTTP client, buffer the body fully, measure its byte length, and set the header explicitly. Concretely: read the file/stream into a string or byte array before sending, rather than handing the client a stream it will chunk. - For empty POSTs, set
Content-Length: 0. If the request legitimately has no body, say so with an explicit zero-length header rather than omitting it. - Check the library’s streaming behavior. Many clients switch to chunked automatically for stream/generator bodies. Pass a fixed buffer, or use the client’s option to compute and send a length.
- If you control the server and don’t want this, decide whether to accept chunked request bodies. Some stacks let you enable it; the trade-off is that you lose the ability to enforce a size limit before buffering.
- Re-test through the same path. If a WAF or proxy is imposing the 411, verify your fix against the real edge, not just a direct-to-origin call.
When to Escalate
- If your client is already sending a correct
Content-Lengthand you still get 411, escalate to whoever runs the proxy or WAF in front of the service — a middlebox may be stripping or rewriting the header before it reaches the origin, and only their logs will show it. - If a third-party API returns 411 for a documented streaming upload, check their docs for a required
Content-Length(or a multipart/resumable alternative) before assuming a bug — many storage APIs deliberately require a declared size and offer a separate chunked-upload protocol of their own.
Related Tools
Related Guides
Share this guide