400 Bad Request HTTP Status Code

Description

The HTTP status code 400, also known as "Bad Request," indicates that the server cannot or will not process the request due to something that is perceived to be a client error. This can mean that the request was malformed, the server could not understand it due to an issue with the request itself, such as incorrect syntax, invalid request message framing, or deceptive request routing.

When a server returns a 400 status code, it is an indication that the request was structured in a way that the server did not understand and therefore could not respond to. This status code is different from the 401 "Unauthorized" or 403 "Forbidden" status codes, as those indicate issues with permissions or access, whereas a 400 error is strictly about the format or content of the request.

The response body accompanying a 400 status code often contains details about the error, providing hints or explanations to help the client understand why the request was considered a bad request. This can be particularly useful during debugging or when developing web services and applications, as it can guide developers in correcting the request format or data.

Status

HTTP
400 Bad Request

Common Causes

Here are the most common causes for a 400 Bad Rquest code:

  1. Incorrect URL Format: If the URL structure is not correctly formatted, the server might not understand the request. This includes missing parameters or path segments.

  2. Malformed Request Syntax: The HTTP request's syntax is invalid. This could involve malformed headers, incorrect request lines, or bad request bodies.

  3. Size Exceeds Limit: Some servers have limitations on the size of the request. If the request body or the headers are too large, the server might reject the request with a 400 error.

  4. Invalid Headers: If the request headers are missing, duplicate, or contain invalid characters, the server may return a 400 error.

  5. Unsupported Media Type: This occurs when the client specifies a Content-Type or encoding that the server does not understand or support.

  6. Invalid Query Parameters: Similar to the URL format issue, if the query parameters attached to the URL are in the wrong format, contain invalid characters, or conflicting data, it could result in a 400 error.

  7. Cookie/Session Issues: Sometimes, issues with cookies or session data can lead to a 400 error, especially if the data is corrupted or improperly formatted.

  8. Cross-Origin Request Blocked: While typically associated with a different set of HTTP status codes (like 403 or CORS policy errors), misconfigured cross-origin requests can sometimes result in a 400 error.

  9. Deceptive Request Routing: If a request is routed in a way that deceives the server or is considered potentially harmful, a server might respond with a 400 error to reject the request.

  10. Invalid JSON/XML: If the request body is JSON or XML, formatting errors, such as missing brackets, commas, or incorrect data types, can cause the server to return a 400 error.

It's important to note that the exact cause can vary based on the server's configuration and the specifics of the request. To resolve a 400 error, one would typically need to closely examine the request being made and correct any discrepancies or errors that could be causing the server to reject the request.

Browser Support

The following table will show you the current browser support for the 400 Bad Request HTTP status code.

Desktop
Edge Chrome Firefox Opera Safari
YesYesYesYesYes
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
YesYesYesYesYesYes

Last updated by CSSPortal on: 1st April 2024