# 406 不可接受：请求的媒体类型不受服务器支持

- **ID:** `api/http-406-not-acceptable-content-negotiation`
- **领域:** api
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| HTTP/1.1 (RFC 7231) | active | — | — |
| Spring Boot 3.0+ | active | — | — |
| ASP.NET Core 8.0+ | active | — | — |

## 解决方案

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` 依赖）来添加对请求媒体类型的支持。
   ```

## 无效尝试

- **** — 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. (60% 失败率)
- **** — The server must explicitly support the requested type; the error is correct. (80% 失败率)
- **** — While `*/*` may work, it bypasses content negotiation and may return an unexpected format. (70% 失败率)
