Error Codes Wiki

Content Negotiation Errors — Accept Header and 406 Not Acceptable Responses

Informational4xx client error

About Content Negotiation Errors

Fix HTTP content negotiation errors where servers return 406 Not Acceptable or wrong content formats due to Accept header mismatches. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.

Here are the key things to understand: 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. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.

The most common reasons this occurs include: 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. Identifying the root cause is the first step toward finding the right solution.

To resolve this, follow these recommended steps: Set the correct Accept header for the expected response format: application/json for REST APIs, text/html for web pages. Use Accept: */* or omit the Accept header to accept any format the server provides. Implement server-side fallback: if no Accept header matches, return the default format instead of 406. Check the Content-Type of the response to verify which format was selected. Test content negotiation: 'curl -H "Accept: application/json" https://api.example.com/resource'. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.

This article is part of our HTTP Status Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.

Quick Answer

What does 406 Not Acceptable mean?

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.

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.