An HTTP 400 Bad Request error means the server couldn’t process the request because something in it was wrong: a malformed URL, cookies that are too large, invalid JSON, or a request sent to the wrong port. The server is working. It just can’t make sense of what it was sent.
This guide explains what the 400 status code means, the most common causes, and how to fix it in the browser, in API requests and on Nginx and Apache servers.
What Does 400 Bad Request Mean?
The HTTP standard (RFC 9110) says a 400 means the server “cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).”
It’s a 4xx client error, so the request needs to change. Sending the same request again gives the same result. You may see it as:
400 Bad RequestorHTTP Error 400400 Bad Request - Request Header Or Cookie Too Large(Nginx)400 Bad Request - The plain HTTP request was sent to HTTPS port(Nginx)Your browser sent a request that this server could not understand.(Apache)Size of a request header field exceeds server limit.(Apache)HTTP Error 400. The request is badly formed.(IIS){"error": "invalid JSON"}or a validation message from an API
Common Causes of a 400 Error
- Cookies or headers that are too large: a site that sets many cookies, or a huge login token, goes past the server’s header size limit.
- A malformed URL: illegal characters, a stray
%that isn’t a valid encoding, or a broken query string. - Invalid request body: broken JSON, a missing required field, or the wrong
Content-Typeheader in an API call. - HTTP sent to an HTTPS port: for example
http://example.com:443/. - A missing or wrong
Hostheader in hand-made or scripted requests. - A corrupted browser cache or session.
Quick Fixes If You’re Visiting the Site
- Check the URL for typos, stray
%signs or extra characters. Re-type it or open the site from its homepage. - Clear the site’s cookies. This fixes “Request Header Or Cookie Too Large” in most cases. In Chrome, click the icon left of the address bar, open the cookie settings for the site and delete them.
- Try a private window. If it works there, the problem is your cookies or cache.
- Clear your browser cache and disable extensions that change requests (privacy or header-editing extensions).
- Check uploaded files: if the error appears when you upload, the file may be too large or the wrong type.
How to Fix 400 Errors in API Requests
Most APIs return 400 with a message that says exactly what’s wrong. Use curl -v or -i to see the full response:
curl -i -X POST https://api.example.com/v1/items -H "Content-Type: application/json" -d '{"name": "test"}'
Check these common mistakes:
- Invalid JSON: trailing commas, single quotes or unescaped characters. Validate the body first, for example with
echo '{"name": "test"}' | jq . - Wrong
Content-Type: sending JSON withoutContent-Type: application/json, or form data with it. - Missing required fields or values of the wrong type (a string where a number is expected).
- Unencoded query parameters: spaces and special characters must be URL-encoded. curl can do this for you with
-G --data-urlencode "q=hello world".
Some APIs use 422 Unprocessable Content instead of 400 when the JSON is valid but the values fail validation.
How to Fix 400 Errors on Your Own Server
“Request Header Or Cookie Too Large” (Nginx)
Nginx reads request headers into buffers set by large_client_header_buffers. The default is 4 8k: four buffers, and no single header line (including the Cookie header) can be longer than 8 KB. If your app legitimately sets large cookies or tokens, raise the limit in the http or server block:
large_client_header_buffers 4 16k;
sudo nginx -t && sudo systemctl reload nginx
It’s better to find out why the cookies are so large. Common causes are analytics or A/B-testing cookies piling up, or session data stored in cookies instead of on the server.
“Size of a request header field exceeds server limit” (Apache)
Apache limits each header line with LimitRequestFieldSize, which defaults to 8190 bytes. Raise it in the main config or virtual host, then restart Apache:
LimitRequestFieldSize 16380
If you use Nginx in front of Apache, or Apache in front of an app server, raise the limit on every layer.
“The plain HTTP request was sent to HTTPS port” (Nginx)
Someone opened the HTTPS port with plain HTTP, for example http://example.com:443/, or a load balancer sends HTTP to a port where Nginx expects TLS. Visitors should use the https:// URL. If it comes from your own load balancer, either send HTTPS to the backend or set the backend’s listen line without ssl. Make sure your redirects go to https://example.com/ without a port number.
Check the logs
400 errors from the web server itself usually appear in the error log with a reason, and in the access log with status 400:
sudo awk '$9 == 400' /var/log/nginx/access.log | tail -n 20sudo grep -i "client sent" /var/log/nginx/error.log | tail
Nginx logs messages such as client sent invalid request or client sent too long header line. A few 400s from bots and scanners sending junk requests are normal and can be ignored.
Fix application validation errors
If your own app returns 400, its log should say which field or value failed. Return a helpful error body to clients, for example:
{"error": "validation_failed", "field": "email", "message": "email is required"}
Related HTTP Error Guides
For the full list of codes and what they mean, see our HTTP status codes list. Guides for other common errors:
- HTTP 401 Unauthorized
- HTTP 403 Forbidden
- HTTP 404 Not Found
- HTTP 429 Too Many Requests
- HTTP 500 Internal Server Error
- HTTP 502 Bad Gateway
- HTTP 503 Service Unavailable
- HTTP 504 Gateway Timeout
Frequently Asked Questions
What does 400 Bad Request mean?
It means the server couldn’t understand or accept the request because something in it was wrong, such as the URL, the cookies or the data sent.
How do I fix a 400 Bad Request in Chrome?
Check the URL, then clear the cookies for that site, or open it in an incognito window. Clearing cookies fixes most cases, especially “Request Header Or Cookie Too Large”.
Is 400 Bad Request a client or server error?
It’s a client error (4xx): the request needs to change. But a misconfigured server, for example one with header limits that are too low, can cause it for valid requests.
What is the difference between 400 and 422?
400 is a general “bad request”. Many APIs use 422 Unprocessable Content when the request’s format is valid but its values fail validation.
What does “Request Header Or Cookie Too Large” mean?
Your browser sent more cookie or header data than the Nginx server accepts (8 KB per header line by default). Clear the site’s cookies. Site owners can raise large_client_header_buffers.
Conclusion
An HTTP 400 Bad Request error means the server couldn’t accept the request as it was sent. For visitors, checking the URL and clearing the site’s cookies fixes most cases. For developers, the response body usually names the problem: invalid JSON, a wrong Content-Type or a missing field. For admins, the logs show whether it’s an oversized header, HTTP sent to the HTTPS port or just bots sending junk.
How did it make you feel?
