HTTP 406 Not Acceptable


The HTTP 406 Not Acceptable status code is used when the server cannot produce a response matching the list of acceptable values defined in the request’s proactive content negotiation headers, such as Accept, Accept-Charset, Accept-Encoding, and Accept-Language.


The HTTP 406 response indicates that the server can generate a response for the requested resource, but that response is not acceptable according to the Accept headers sent in the request.


Client Behavior:

  1. Send Request with Accept Headers: The client sends an HTTP request including headers like Accept to specify the response formats it is willing to receive.
  2. Receive Response: The client receives the HTTP 406 status code if the server cannot provide a response in any of the acceptable formats.

Server Behavior:

  1. Evaluate Accept Headers: The server evaluates the request’s Accept headers against its capabilities to produce a response.
  2. Send Response: If no acceptable formats are available, the server sends a 406 Not Acceptable response.


  • Content Negotiation: When the client specifies a particular format for the response which the server cannot fulfill.
  • Limited Resource Formats: Resources that are only available in formats not acceptable to the client.

Sequence Diagram

Illustrating the process for an HTTP 406 response:

    participant Client
    participant Server as Web Server

    Note over Client: Client requests with specific accept headers
    Client->>Server: GET /resource HTTP/1.1
    Client->>Server: Accept: application/xml
    Note over Server: Server cannot provide XML format
    Server->>Client: HTTP/1.1 406 Not Acceptable

Curl Request and Response Example

Requesting a resource with specific Accept headers using Curl:

curl -i -H "Accept: application/xml"
# Expected response: HTTP/1.1 406 Not Acceptable

PHP cURL Request and Response Example

PHP script using cURL to handle a 406 Not Acceptable response:

$ch = curl_init('');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/xml'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 406) {
    echo "Requested format not acceptable.";

Python Request and Response Example

Python script to send a GET request with specific Accept headers and handle a 406 Not Acceptable response:

import requests
headers = {'Accept': 'application/xml'}
response = requests.get('', headers=headers)
if response.status_code == 406:
    print("Requested format not acceptable")

Apache Configuration for HTTP 406 Not Acceptable

Configuring Apache to handle content negotiation and 406 responses:

<VirtualHost *:80>
    # Configuration for content negotiation and handling 406 Not Acceptable
    # ...

NGINX Configuration for HTTP 406 Not Acceptable

Setting up NGINX to manage content negotiation and 406 responses:

server {
    listen 80;
    location /resource {
        # Directives for handling different Accept headers
        # ...

HTTP 405 Method Not Allowed HTTP 407 Proxy Authentication Required


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.