HTTP 400 Bad Request


The HTTP 400 Bad Request status code indicates that 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).


The HTTP 400 response is used to signify that the server identified an error in the client’s request. It is a generic error response for situations where the specific error is not suitable for disclosure to the client.


Client Behavior:

  1. Send Request: The client sends an HTTP request to the server.
  2. Receive Response: The client receives the HTTP 400 status code, indicating an issue with the request.

Server Behavior:

  1. Evaluate Request: The server evaluates the client’s request.
  2. Send Response: If the server finds an issue with the request, it sends a 400 Bad Request response, typically with details about the error.


  • Malformed Syntax: When the request has syntax errors or is malformed.
  • Invalid Parameters: Requests with invalid parameters or query strings.
  • Deceptive Routing: If the request attempts deceptive routing or contains misleading fields.

Sequence Diagram

Illustrating the process for an HTTP 400 response:

    participant Client
    participant Server as Web Server

    Note over Client: Client sends a malformed request
    Client->>Server: GET /resource?invalid=param HTTP/1.1
    Note over Server: Server evaluates and finds an error
    Server->>Client: HTTP/1.1 400 Bad Request

Curl Request and Response Example

Sending a malformed request using Curl to simulate a 400 Bad Request:

curl -i
# Expected response: HTTP/1.1 400 Bad Request

PHP cURL Request and Response Example

PHP script using cURL to handle a response for a bad request:

$ch = curl_init('');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 400) {
    echo "Bad request error.";

Python Request and Response Example

Python script to send a GET request that results in a 400 Bad Request response:

import requests
response = requests.get('', params={'invalid': 'param'})
if response.status_code == 400:
    print("Bad request error")

Apache Configuration for HTTP 400 Bad Request

Apache server configuration to handle bad requests:

<VirtualHost *:80>
    # Additional configurations for handling bad requests
    # ...

NGINX Configuration for HTTP 400 Bad Request

Setting up NGINX to properly respond to bad requests:

server {
    listen 80;
    location / {
        # Configurations to handle malformed requests
        # ...

HTTP 308 Permanent Redirect (Experimental) HTTP 401 Unauthorized


Free Weekly


Join my weekly newsletter for the latest in tech! You'll get neat coding tricks, trend updates, career advice, SaaS reviews, crypto, bitcoin, and financial tips. All straight to your inbox, designed to keep you ahead.