411 Length Required: what it means and how to fix it

A 411 means the server wants a Content-Length header and the request did not have one. Why it happens with curl, chunked uploads and proxies, and the fixes.

· 5 min read · By the Spot Downtime team

411 Length Required is a client error. The server refuses to process the request because it has noContent-Length header, and the server requires one for this resource. It is rare on modern stacks, but when it does appear it is usually from one of three places: a command-line client, a streaming upload, or a proxy in the middle.

What the server is asking for

An HTTP/1.1 request with a body must tell the server where the body ends. It does that in one of two ways: a Content-Length header with the size in bytes, or Transfer-Encoding: chunked, which sends the body in pieces with no total up front. A 411 says the server accepts neither of those for this request, and wants the first.

The fix is to send the length. Sending the same request again without changes gets the same answer, so retrying is pointless.

Common causes

A POST or PUT with no body

Some servers insist on Content-Length: 0 for a POST or PUT without a body. Many clients leave the header out when there is no body, and a strict server answers 411.

bash
# May return 411 on a strict server: no body, no Content-Length
curl -i -X POST https://api.example.com/jobs/42/start

# Sends Content-Length: 0
curl -i -X POST -d "" https://api.example.com/jobs/42/start

# Or set it explicitly
curl -i -X POST -H "Content-Length: 0" https://api.example.com/jobs/42/start

A chunked upload to a server that does not accept it

Clients switch to chunked encoding when they stream a body of unknown size: a generator, a pipe, or a file read on the fly. Not every server or gateway handles chunked request bodies. Some object storage APIs, older application servers and embedded devices need a length up front and reply with 411.

python
import requests

# A generator has no known length, so requests uses chunked encoding
def chunks():
    yield b"part one"
    yield b"part two"

requests.post(url, data=chunks())      # chunked: may get 411

# A bytes object has a known length, so requests sends Content-Length
requests.post(url, data=b"part onepart two")

With a file, pass the open file object. requests reads its size and sends the header. If you stream from a source of unknown length, buffer it first (to memory or a temporary file) so you can compute the size, or switch to an API that supports multipart uploads.

A proxy or gateway in between

A reverse proxy, API gateway or CDN may strip, rewrite or reject headers. If the client sends chunked data and the next hop in the chain only accepts length-delimited bodies, the proxy returns the 411, or passes the origin's 411 through. Look at which hop generated the response: the Server and Via headers and the error page body usually say.

Wrong header after redirects or middleware

A client or middleware that edits the body, for instance by compressing or re-encoding it, without updatingContent-Length can send a wrong or missing value. Wrong lengths cause hangs and resets as often as 411, so check the header against the real body size.

How to reproduce and inspect

Use curl with verbose output to see exactly which headers are sent:

bash
curl -v -X POST --data-binary @payload.json \
  -H "Content-Type: application/json" https://api.example.com/items

# Force chunked encoding to compare
curl -v -X POST -T payload.json \
  -H "Transfer-Encoding: chunked" https://api.example.com/items

In the first request curl adds Content-Length itself. If that call succeeds and the chunked one returns 411, you have confirmed that the server needs a length.

Fixes for the client

  • Send a body with a known size, or send Content-Length: 0 explicitly for bodyless POST and PUT calls.
  • Avoid streaming from unknown-length sources to servers that do not support chunked encoding. Buffer, then send.
  • Check HTTP library defaults. Some switch to chunked as soon as the body is a stream or generator.
  • For large files, use the service's multipart or resumable upload feature, which sends parts with known sizes.

Fixes for the server owner

If you run the server and clients get 411 from your side, decide whether you really need to demand a length. Modern servers and frameworks accept chunked bodies. If your gateway or application server does not, check its documentation for a setting that enables request buffering or chunked support. In nginx, request bodies sent with chunked encoding are accepted and buffered, and the practical limit is client_max_body_size. Hitting that limit returns a different error; see 413 Content Too Large.

Do not confuse these

411 is about a missing length. 400 Bad Request covers a malformed or contradictory one, such as a Content-Length that does not match the body, and 415 is about the content type.

Monitoring POST endpoints

If you monitor an API with POST or PUT checks, include a body or an explicit zero length so strict gateways do not reject the check itself. Then set the expected status to the code a correct request returns, so a gateway change that starts returning 411 shows up as a failed check. An API monitor lets you set the method, headers and body for this.

HTTP headers checkerInspect the response headers of a URL to see which server or proxy answered.

Get new guides by email

Practical posts on monitoring, outages, error fixes and on-call, when they're published. No spam.

Unsubscribe from any email with one click. See our privacy policy.

Keep reading