406 Not Acceptable
HTTP response status code 406 Not Acceptable is a client error that is returned by the server to indicate that the resource exists but the proactive Content Negotiation engaged in by the client using a relevant HTTP request header was not satisfiable and the server does not supply a default in lieu.
When the 406 Not Acceptable error message is received, it is in response to an HTTP request that includes a negation-related header such as Accept or Accept-Language. When the client includes one or more of these headers, the server will satisfy the requirements if possible.
The most common HTTP Accept headers are:
Accept: Specifies the type of content. For example, a server may be willing to supply either plain text or an HTML representation. In the example, the client prefers HTML but is willing to accept plain text.
Accept: text/html, text/plain
Accept-Charset: Specifies the character set, which allows for special-purpose character sets to be requested of a server that supports them. In the example, the client is requesting UTF-8 be the character set used for the response.
Accept-Datetime: The client uses this header to indicate that it wants a past state of this resource, as specified by the date. In the example, the client is requesting a copy of the resource that was available on January 1st, 2021.
Accept-Datetime: Fri, 1 Jan 2021 00:00:00 GMT
In practice, this error is rarely used because the server supplies a default representation instead. The rationale is that it assumes that the client will prefer something over nothing. However, when the 406 Not Acceptable response is returned, the message body will contain a list of available representations that the client can choose from.
Search engines like Google will not index a URL with 406 Not Acceptable response status, and consequently, URLs that have been indexed in the past but are now returning this HTTP status code will be removed from the search results.
In the example, the client requests a resource in the French language but the server responds with the 406 Not Acceptable response because only German and English versions of the document are available.
GET /news HTTP/1.1 Host: www.example.re Accept-Language: fr
HTTP/1.1 406 Method Not Acceptable Content-Type: text/html Content-Length: 242 <html> <head> <title>French Language Not Available</title> </head> <body> <p>Please choose a supported language:</p> <p><a href="/news/news-de.html">German</a></p> <p><a href="/news/news-en.html">English</a></p> </body> </html>
Apache HttpComponents Core
The 406 Not Acceptable status code is a client error that is returned when the client-specified proactive negotiation requirements cannot be satisfied, and the server is unwilling to send a default representation.