Skip to content

411 Length Required

The server refuses the request because it has a body but no Content-Length header saying how big that body is.

What 411 Length Required means

Some servers need to know the body size up front and reject requests that omit it or use chunked transfer encoding.

The client can retry once it adds a valid Content-Length header.

Common causes

  • A POST or PUT sent with chunked encoding to a server that does not accept it.
  • A hand-built request or client library that leaves out the header, often on an empty POST.

How to fix 411 Length Required

  1. Send a Content-Length that matches the body size in bytes (Content-Length: 0 for an empty body).
  2. Buffer the body before sending instead of streaming it, so the length is known.

Headers that go with it

  • Content-Length
  • Transfer-Encoding

Example response

HTTP/1.1 411 Length Required
Content-Type: text/plain; charset=utf-8

411 Length Required

How to check for a 411 response

cURL

# Print only the status code
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/

JavaScript (Node.js)

const res = await fetch("https://example.com/");
if (res.status === 411) {
  console.log(res.status, res.statusText);
}

Python

import requests

res = requests.get("https://example.com/")
if res.status_code == 411:
    print(res.status_code, res.reason)

Go

res, err := http.Get("https://example.com/")
if err != nil {
	log.Fatal(err)
}
defer res.Body.Close()
if res.StatusCode == 411 {
	fmt.Println(res.Status)
}

Specification

411 Length Required is defined in RFC 9110, section 15.5.12.

  • 413

    Content Too Large

    The request body is bigger than the server is willing to accept, usually because an upload is over the size limit.

  • 400

    Bad Request

    The server could not understand the request because something in it is malformed, like broken JSON, bad syntax or invalid headers.

  • 412

    Precondition Failed

    A condition in the request headers, such as If-Match or If-Unmodified-Since, was false, so the server did not apply the request.

← all 63 HTTP status codes

Type to search posts, tools and projects.

Keyboard shortcuts

Search+Kor/
Go to homegthenh
Go to bloggthenb
Go to projectsgthenp
Go to timelinegthent
Show this help?
Close search or helpesc