api protocol_error ai_generated true

406 Not Acceptable: requested media type not supported by server

ID: api/http-406-not-acceptable-content-negotiation

Also available as: JSON · Markdown · 中文
90%Fix Rate
88%Confidence
1Evidence
2023-11-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
HTTP/1.1 (RFC 7231) active
Spring Boot 3.0+ active
ASP.NET Core 8.0+ active

Root Cause

The client's `Accept` header specifies a media type (e.g., `application/xml`) that the server cannot produce, causing content negotiation to fail.

generic

中文

客户端的 `Accept` 头指定了服务器无法生成的媒体类型(例如 `application/xml`),导致内容协商失败。

Official Documentation

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/406

Workarounds

  1. 95% success Set the `Accept` header to a supported type, typically `application/json`. Example: `curl -H "Accept: application/json" https://api.example.com/resource`.
    Set the `Accept` header to a supported type, typically `application/json`. Example: `curl -H "Accept: application/json" https://api.example.com/resource`.
  2. 90% success Check the server's API documentation for supported media types and update the client accordingly. Example: `GET /api/v1/resource` with `Accept: application/vnd.api+json`.
    Check the server's API documentation for supported media types and update the client accordingly. Example: `GET /api/v1/resource` with `Accept: application/vnd.api+json`.
  3. 85% success If you control the server, add support for the requested media type by configuring a content negotiation serializer (e.g., in Spring Boot, add `jackson-dataformat-xml` dependency).
    If you control the server, add support for the requested media type by configuring a content negotiation serializer (e.g., in Spring Boot, add `jackson-dataformat-xml` dependency).

中文步骤

  1. 将 `Accept` 头设置为受支持的类型,通常是 `application/json`。示例:`curl -H "Accept: application/json" https://api.example.com/resource`。
  2. 查看服务器 API 文档以了解支持的媒体类型,并相应更新客户端。示例:`GET /api/v1/resource` 使用 `Accept: application/vnd.api+json`。
  3. 如果您控制服务器,通过配置内容协商序列化器(例如,在 Spring Boot 中添加 `jackson-dataformat-xml` 依赖)来添加对请求媒体类型的支持。

Dead Ends

Common approaches that don't work:

  1. 60% fail

    The server may still default to a supported type (e.g., `application/json`), but if the client explicitly requires a type, removing the header changes behavior and may cause other issues.

  2. 80% fail

    The server must explicitly support the requested type; the error is correct.

  3. 70% fail

    While `*/*` may work, it bypasses content negotiation and may return an unexpected format.