Languages
[Edit]
EN

HTTP - status: 406 Not Acceptable

13 points
Created by:
Nikki-Mathews
517

In this short article we would like to explain what  406 Not Acceptable status means in HTTP response and when occurs.

When server returns status 406 for HTTP request (Not Acceptable) it means the server is not albe to match acceptable values located in headers in client request.

During negotation can be used following headers:

  • Accept
  • Accept-Charset
  • Accept-Encoding
  • Accept-Language

Practical example

Let's suppose client sends following headers (user web browser tells that is able to handle only value combinations from headers):

Accept: application/json
Accept-Charset: utf-8, iso-8859-1;q=0.5
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9

Server is not able to provide any combination from Accept citeria and returns 406 status.

Any combination means:

Accept             Accept-Charset   Accept-Encoding   Accept-Language

application/json   utf-8            gzip              en-US
application/json   utf-8            deflate           en-US
application/json   iso-8859-1       deflate           en

etc.

Example web browser request:

GET /backend/45a62d3d/download HTTP/1.1
Host: 192.168.0.50:8080
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: application/json
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36
Content-Type: application/json
Origin: http://localhost:8000
Referer: http://localhost:8000/downloads
Accept-Charset: utf-8, iso-8859-1;q=0.5
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9

Example server response:

HTTP/1.1 406
Server: nginx/1.18.0
Date: Wed, 02 Sep 2020 09:46:31 GMT
Content-Length: 0
Connection: keep-alive
Cache-Control: private
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Access-Control-Allow-Origin: http://localhost:8000
Access-Control-Allow-Credentials: true

Amount of reasones why server is not able to proceed with user requirements can be different, but as example we can use: lack of support for application/json MIME type - user expected JSON response for XHR / Ajax request.

Solutions:

  • as server owner you can provide following response by proper response implementation,
  • or requester can change request requirements and asks with different MIME type.

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

HTML

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join