Error Codes Wiki

Content Negotiation Errors — Accept Header and 406 Not Acceptable Responses

Informational4xx client error

Overview

Fix HTTP content negotiation errors where servers return 406 Not Acceptable or wrong content formats due to Accept header mismatches.

Key Details

  • Content negotiation allows clients to specify preferred response formats using Accept headers
  • Accept: application/json requests JSON; Accept: text/html requests HTML; Accept: */* accepts any format
  • 406 Not Acceptable is returned when the server cannot produce a response matching the Accept header
  • Quality values (q=0.9) indicate preference order: Accept: application/json;q=1, text/html;q=0.5
  • Content-Type in the response indicates which format was chosen by the server

Common Causes

  • Client sending Accept: application/json to an endpoint that only returns HTML
  • Server strictly enforcing Accept headers instead of falling back to a default format
  • Accept header malformed — missing commas between media types or invalid quality values
  • API documentation specifying a different Accept header than what the server actually expects

Steps

  1. 1Set the correct Accept header for the expected response format: application/json for REST APIs, text/html for web pages
  2. 2Use Accept: */* or omit the Accept header to accept any format the server provides
  3. 3Implement server-side fallback: if no Accept header matches, return the default format instead of 406
  4. 4Check the Content-Type of the response to verify which format was selected
  5. 5Test content negotiation: 'curl -H "Accept: application/json" https://api.example.com/resource'

Tags

content-negotiationaccept406media-typeformat

More in 4xx Client Error

Frequently Asked Questions

The server cannot produce a response in any format acceptable to the client based on the Accept header. Either the client needs to accept additional formats or the server needs to support the requested format.