What is HTTP Response Status Code 406 Not Acceptable?
HTTP response status code 406 Not Acceptable indicates that the server cannot produce a response that matches the criteria specified in the client’s Accept
headers.
This status code is used when the client requests a specific content type or format that the server cannot provide, such as requesting JSON when only XML is available.
The server may include information about supported media types in the response, allowing the client to adjust their request to match an acceptable type.
It helps ensure that clients receive responses in the desired format while also guiding them on what formats are supported by the server.
Example 1: Client Requests Unsupported Media Type
# Client sends a request specifying only XML as an acceptable response format. GET /api/data HTTP/1.1 Host: api.example.com Accept: application/xml # Server Response HTTP/1.1 406 Not Acceptable Date: Wed, 09 Oct 2024 14:35:00 GMT Server: Apache/2.4.41 (Ubuntu) Content-Type: application/json { "error": "Requested format is not available. Supported formats: application/json" }
Example 2: Client Requests Unsupported Language
# Client sends a request with an Accept-Language header for a language not supported by the server. GET /content HTTP/1.1 Host: www.example.com Accept-Language: fr # Server Response HTTP/1.1 406 Not Acceptable Date: Wed, 09 Oct 2024 14:37:00 GMT Server: Nginx/1.18.0 { "error": "The requested language is not supported. Available languages: en, es." }
Summary
The HTTP 406 Not Acceptable status code ensures that servers only deliver responses in formats that meet client preferences. It allows clients to adjust their requests to match available content types or languages supported by the server.