HTTP status code 411 indicates that the server refuses to accept the request without a defined Content-Length
. The Content-Length
header is necessary for the server to know the size of the request body, which is essential for processing the request correctly.
Common Scenarios for 411 Status Code
- Missing Header: When a client sends a request with a body but omits the
Content-Length
header. - Chunked Transfer Encoding Not Supported: If the server does not support chunked transfer encoding and the request does not specify the content length.
- Server Configuration: Some servers are configured to require a
Content-Length
header for all requests that include a body. - Multipart/Form-Data: When uploading files or submitting forms, if the
Content-Length
is not specified, the server may not process the request.
Characteristics of 411 Length Required
- Client Error: A 411 status code is a client error, indicating an issue with the request.
- Required Header: The server expects the
Content-Length
header to be present in the request. - Impact on Request Processing: Without the
Content-Length
, the server may not read the entire request body, leading to a malformed request. - Non-Standard Behavior: According to the HTTP specification, it is not mandatory for servers to understand
Content-Length
. However, many require it for requests with bodies.
Example Response
HTTP/1.1 411 Length Required
Content-Type: text/html
Content-Length: 160
<html>
<head><title>411 Length Required</title></head>
<body>
<h1>411 Length Required</h1>
<p>The server refuses to accept the request without a defined <code>Content-Length</code>.</p>
</body>
</html>
In this example, the server indicates that it will not process the request due to the missing Content-Length
header. The client should resend the request with the appropriate Content-Length
header.
Note: When encountering a 411 Length Required status, clients should review their requests to ensure that they include the
Content-Length
header when sending a request body. This is particularly important formultipart/form-data
or other requests with bodies. Additionally, if the request body is dynamically generated, it is crucial to ensure that theContent-Length
is correctly calculated and included for successful communication with the server.
Related 4xx error code
- 400 Bad Request
- 401 Unauthorized
- 402 Payment Required
- 403 Forbidden
- 404 Not Found
- 405 Method Not Allowed
- 406 Not Acceptable
- 407 Proxy Authentication Required
- 408 Request Timeout
- 409 Conflict
- 410 Gone
- 412 Precondition Failed
- 413 Payload Too Large
- 414 URI Too Long
- 415 Unsupported Media Type
- 416 Range Not Satisfiable
- 417 Expectation Failed
- 418 I’m a teapot
- 421 Misdirected Request
- 422 Unprocessable Entity (WebDAV)
- 423 Locked (WebDAV)
- 424 Failed Dependency (WebDAV)
- 425 Too Early
- 426 Upgrade Required
- 428 Precondition Required
- 429 Too Many Requests
- 431 Request Header Fields Too Large
- 451 Unavailable For Legal Reasons
- 499 Client Closed Request