411 Length Required
The server refuses to accept the request without a defined Content-Length header.
Meaning & Description
Common Causes
- Missing Content-Length header on a request that contains a body.
- Using Transfer-Encoding: chunked on an endpoint that requires a fixed content length.
- A strict server configuration (like Nginx or HAProxy) rejecting body-less POST requests without a length header.
How to fix a 411 error
- Check your HTTP client to ensure it automatically calculates and appends the Content-Length header.
- If sending an empty body, explicitly set `Content-Length: 0`.
- Verify that intermediate load balancers or proxies are not stripping the header.
Browser & SEO Behaviour
Browser Behavior
Browsers automatically calculate and append the Content-Length header for form submissions and fetch/XHR requests containing a body.
SEO Impact
No direct SEO impact, as crawlers generally issue GET requests which do not require a Content-Length. If a crawler encounters this, it signals a server misconfiguration for GET routes.
CDN Behavior
CDNs will typically pass this response directly to the client. Some WAFs might proactively return a 411 if they are configured to block chunked requests.
Code Examples
HTTP/1.1 411 Length Required
Content-Type: text/plain
Connection: close
Content-Length header is missing.app.post("/upload", (req, res) => {
if (!req.headers["content-length"]) {
return res.status(411).send("Content-Length header is required.");
}
// Process upload...
});from fastapi import FastAPI, Request, HTTPException
app = FastAPI()
@app.post("/submit")
async def submit_data(request: Request):
if "content-length" not in request.headers:
raise HTTPException(status_code=411, detail="Length Required")
return {"message": "Success"}func handler(w http.ResponseWriter, r *http.Request) {
if r.ContentLength == -1 {
http.Error(w, "Length Required", http.StatusLengthRequired)
return
}
w.WriteHeader(http.StatusOK)
}[HttpPost("data")]
public IActionResult PostData()
{
if (!Request.Headers.ContainsKey("Content-Length"))
{
return StatusCode(411, "Content-Length header missing");
}
return Ok();
}# Adding Content-Length explicitly for an empty POST
curl -X POST -H "Content-Length: 0" https://api.example.com/triggerRaw HTTP Response Example
HTTP/1.1 411 Length Required
Date: Wed, 21 Oct 2026 07:28:00 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 42
Request must include Content-Length headerReal-world Examples
Frequently Asked Questions
Why am I getting a 411 error when my request has no body?
Some strict servers require a Content-Length header on all POST or PUT requests, even if the body is empty. You can resolve this by explicitly sending `Content-Length: 0`.
Does Transfer-Encoding: chunked replace Content-Length?
Yes, in HTTP/1.1, you cannot use both simultaneously. If a server does not support chunked encoding, it will reject the request with a 411 status and demand a Content-Length instead.
How do I fix a 411 error in cURL?
Add the header manually using `-H "Content-Length: 0"` if you are sending an empty POST request, or ensure you are passing data correctly with the `-d` flag, which makes cURL calculate it automatically.
Should a GET request ever receive a 411 status?
No. GET requests normally do not contain a body, so a Content-Length is not expected. If a GET request receives a 411, the server is likely misconfigured.
Is a 411 error a client or server issue?
It is a client error (4xx) because the client failed to provide a required header. However, it can feel like a server issue if the server has unusually strict requirements.
Did You Know?
The 411 status code was designed to protect servers from buffer overflow attacks and resource exhaustion.
HTTP/2 and HTTP/3 handle framing and payload length differently at the protocol level, making 411 mostly relevant for HTTP/1.1 traffic.
Developer Tips
- Always ensure your HTTP client library is up to date, as modern libraries handle Content-Length calculation automatically.
- If proxying requests, be careful not to strip Content-Length headers unless you are deliberately switching to chunked transfer encoding.
- For API endpoints that only trigger actions and do not need a payload, accept POSTs with `Content-Length: 0` gracefully.
Interview Questions
These are questions you might face in a backend or API design interview that touch on HTTP 411.
What is the purpose of the 411 Length Required status code?
It informs the client that the server refuses to process the request without a valid Content-Length header. This usually happens when the server needs to know the exact payload size before accepting a POST or PUT request, often to allocate resources safely.
How does Transfer-Encoding interact with the 411 status code?
If a client uses `Transfer-Encoding: chunked`, it omits the Content-Length header. If the server does not support chunked encoding, it will respond with a 411, demanding that the client resend the request with a known Content-Length.
Can a server return a 411 on a GET request?
Technically yes, but it violates HTTP semantics. GET requests should not carry a payload, so requiring a Content-Length is incorrect. Doing so indicates a misconfigured server.
Common Interview Mistakes
- Confusing 411 (Length Required) with 413 (Payload Too Large). 411 means the size is unknown; 413 means the size is known but too big.
- Assuming that GET requests need a Content-Length of 0. GET requests should simply omit the header entirely.
- Thinking that 411 is a server error (5xx) because the server refused the request. It is a client error because the request lacked a required header.