Skip to content

411 Length Required

Description

The 411 Length Required status code indicates that the server refuses to accept the request without a defined Content-Length header field. This status code is returned when a server requires the content length of the request body to be specified before processing the request.

This status code is commonly used when: - A client sends a PUT or POST request without specifying the size of the request body - A server needs to allocate resources based on the size of the incoming request - A server needs to validate the size of the request before processing it - A server implements security measures that require knowing the request size upfront

The 411 Length Required status helps servers manage resources efficiently and protect against certain types of attacks by ensuring they know the size of incoming data before processing it.

Syntax

The server responds with a 411 Length Required status:

HTTP/1.1 411 Length Required
Content-Type: application/json
Content-Length: [length in bytes]

{
  "error": "Length Required",
  "message": "Content-Length header is required for this request"
}

Examples

File Upload Example

A client attempts to upload a file without specifying the content length:

Client Request:

POST /upload HTTP/1.1
Host: files.example.com
Content-Type: application/octet-stream
Transfer-Encoding: chunked

[File data...]

Server Response:

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

{
  "error": "Length Required",
  "message": "Content-Length header is required for file uploads",
  "details": "Please specify the exact size of the file you are uploading"
}

API Resource Creation Example

A client attempts to create a resource without specifying the content length:

Client Request:

POST /api/products HTTP/1.1
Host: api.example.com
Content-Type: application/json
Transfer-Encoding: chunked

{
  "name": "New Product",
  "price": 29.99,
  "description": "This is a new product"
}

Server Response:

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

{
  "error": "Length Required",
  "message": "All POST requests to this API must include a Content-Length header"
}

Data Processing Example

A client attempts to submit data for processing without specifying the content length:

Client Request:

PUT /data/process HTTP/1.1
Host: processing.example.org
Content-Type: text/csv
Transfer-Encoding: chunked

id,name,value
1,Item 1,100
2,Item 2,200
...

Server Response:

HTTP/1.1 411 Length Required
Content-Type: text/html
Content-Length: 245

<!DOCTYPE html>
<html>
<head>
  <title>Length Required</title>
</head>
<body>
  <h1>411 Length Required</h1>
  <p>This server requires a Content-Length header for all data processing requests.</p>
  <p>Please specify the size of your data in bytes and try again.</p>
</body>
</html>

Summary

The 411 Length Required status code is a specific client error response that helps servers manage resources efficiently by requiring clients to specify the size of their request bodies. This allows servers to allocate appropriate resources, validate request sizes against limits, and protect against certain types of attacks. While modern HTTP implementations often support chunked transfer encoding as an alternative to specifying content length, some servers still require explicit content length for security, resource management, or compatibility reasons.