Skip to content

400 Bad Request

The server could not understand the request because something in it is malformed, like broken JSON, bad syntax or invalid headers.

What 400 Bad Request means

400 is the general client error. The server is saying the request itself is wrong, so sending it again unchanged will not help.

It is broader than 422, which means the syntax was fine but the data failed validation, and 415, which is about the body's format. Plenty of APIs still use 400 for validation errors too.

Common causes

  • Malformed JSON, or a body that does not match its Content-Type header.
  • Corrupt or oversized cookies sent by the browser.
  • Invalid characters in the URL, or a query string the server cannot parse.
  • Missing required parameters in an API call.

How to fix 400 Bad Request

  1. As a visitor, check the URL for typos, then clear cookies and cache for that site and try again.
  2. As a developer, read the response body: most APIs say which field or header is wrong.
  3. Validate JSON before sending it and set Content-Type: application/json to match.
  4. Check the logs of any proxy in front of the app too, since nginx and load balancers can return 400 for bad headers before your code runs.

Example response

HTTP/1.1 400 Bad Request
Content-Type: text/plain; charset=utf-8

400 Bad Request

How to check for a 400 response

cURL

# Print only the status code
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/

JavaScript (Node.js)

const res = await fetch("https://example.com/");
if (res.status === 400) {
  console.log(res.status, res.statusText);
}

Python

import requests

res = requests.get("https://example.com/")
if res.status_code == 400:
    print(res.status_code, res.reason)

Go

res, err := http.Get("https://example.com/")
if err != nil {
	log.Fatal(err)
}
defer res.Body.Close()
if res.StatusCode == 400 {
	fmt.Println(res.Status)
}

Specification

400 Bad Request is defined in RFC 9110, section 15.5.1.

  • 422

    Unprocessable Content

    The server understood the request and its format, but the data inside failed validation, like a missing field or bad email.

  • 415

    Unsupported Media Type

    The server refuses the request body because its format, given by Content-Type or Content-Encoding, is not supported.

  • 431

    Request Header Fields Too Large

    The server refuses the request because its headers are too big, usually because of too many or oversized cookies.

  • 413

    Content Too Large

    The request body is bigger than the server is willing to accept, usually because an upload is over the size limit.

← all 63 HTTP status codes

Type to search posts, tools and projects.

Keyboard shortcuts

Search+Kor/
Go to homegthenh
Go to bloggthenb
Go to projectsgthenp
Go to timelinegthent
Show this help?
Close search or helpesc