Skip to content

411 Length Required — Meaning, Common Causes & How to Fix

411 4xx Client Error RFC 9110 §15.5.12

411 Length Required means: The server refuses the request because it lacks a defined Content-Length. The client may retry after adding a valid Content-Length header; chunked transfer without length is unacceptable to this particular endpoint. Client-error 4xx codes mean the request itself is the problem: malformed syntax, missing credentials, forbidden access, a nonexistent resource or a violated precondition. The server is telling the client what to change; retrying the identical request without a fix will reproduce the same error. In practice you will meet 411 when a post/put sent with chunked encoding to a server that requires length; an old cgi or embedded server that cannot handle transfer-encoding: chunked; a client library streaming a body without computing its length. On the client side, buffer the body and send Content-Length, or disable chunked transfer in the client; for curl, avoid -H 'Transfer-Encoding: chunked' unless supported. On the server side, modern servers should accept chunked encoding; emit 411 only when length is genuinely required (e.g. legacy upload handlers).

Advertisement
Ad slot · ref-top

When 411 happens

  • A POST/PUT sent with chunked encoding to a server that requires length
  • An old CGI or embedded server that cannot handle Transfer-Encoding: chunked
  • A client library streaming a body without computing its length

How to fix it

On the client

Buffer the body and send Content-Length, or disable chunked transfer in the client; for curl, avoid -H 'Transfer-Encoding: chunked' unless supported.

On the server

Modern servers should accept chunked encoding; emit 411 only when length is genuinely required (e.g. legacy upload handlers).

Should you retry?

Not retryable as-is: change the request (credentials, payload, URL) first.

Debugging steps

When 411 appears unexpectedly, start by capturing the full exchange: 'curl -i' or the browser DevTools Network tab shows the exact status line and response headers, which often carry the real explanation. Read the error body first — well-designed APIs name the offending field or missing credential. Then diff your actual request, headers included, against the documented contract. For this code specifically, check whether the most common trigger applies to your situation: a post/put sent with chunked encoding to a server that requires length. Compare your exchange against the raw HTTP example above. If you operate the server, correlate the timestamp with application and proxy logs using the request id; if you are the client, verify the request shape against the API documentation before changing anything or retrying.

Notes & gotchas

411 is an HTTP/1.1-era concern: HTTP/2 and HTTP/3 have their own framing and no chunked encoding, so modern stacks rarely need to demand Content-Length.

Examples

Raw HTTP
HTTP/1.1 411 Length Required
Content-Type: application/json
Content-Length: 119

{
  "error": "length_required",
  "message": "A POST/PUT sent with chunked encoding to a server that requires length"
}
curl
curl -i https://api.example.com/v1/resource   # observe the 411 response and its headers
JavaScript (fetch)
const res = await fetch("https://api.example.com/v1/resource");
if (res.status === 411) {
  const problem = await res.json(); // read field-level details
  // fix the request (credentials, payload, URL) — identical retries keep failing
  throw new RequestError(problem);
}
Python (requests)
import requests

res = requests.get("https://api.example.com/v1/resource", timeout=10)
if res.status_code == 411:
    problem = res.json()  # field-level error details
    # correct the request before retrying — identical retries keep failing
    raise RequestProblem(problem)

Frequently asked questions

Why would a server demand Content-Length?

Legacy handlers allocate buffers by length and cannot stream; some upload APIs also need it for quota checks before reading the body.

Does HTTP/2 use Content-Length?

HTTP/2 has its own framing and no chunked encoding; Content-Length is optional metadata. 411 is essentially an HTTP/1.1-era concern.

Are 4xx errors always the client's fault?

By contract yes — the server asserts the request must change. In practice servers sometimes misuse 4xx for their own problems (e.g. 400 for internal validation bugs), so read the error body before blaming your client code.

Should I retry 4xx responses automatically?

Generally no: the server says the request must change. Exceptions are 408 (fresh connection), 425 (after handshake) and 429 (after Retry-After). Blind retries of 400/401/403/404 just burn quota.

Advertisement
Ad slot · ref-in-article

Try the JSON Validator

Check JSON syntax and locate errors by line and column.

Open tool →