# 406 不可接受：Accept 头中指定的 API 版本不受支持

- **ID:** `api/rest-api-version-header-missing-accept`
- **领域:** api
- **类别:** version_error
- **错误码:** `406`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

客户端发送的 Accept 头包含的媒体类型中指定了服务器无法识别或不提供的 API 版本（例如 application/vnd.myapp.v2+json）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| REST API versioning via Accept header | active | — | — |
| ASP.NET Core 8.0 | active | — | — |
| Spring MVC 6.1 | active | — | — |
| Express.js 4.18 | active | — | — |

## 解决方案

1. ```
   通过查看 API 文档或查询版本发现端点，验证服务器支持的确切版本字符串。使用正确的媒体类型，例如 v1 版本使用 application/vnd.myapp.v1+json。
   ```
2. ```
   如果 API 使用基于 URL 的版本控制方案（例如 /api/v1/），则切换为使用该方案而不是 Accept 头版本控制。许多 API 同时支持这两种方法。
   ```

## 无效尝试

- **** — Without the Accept header, the server may default to the latest version or return a generic response, but this defeats version negotiation and may cause unexpected behavior. (70% 失败率)
- **** — The server may interpret application/json as the latest version, but if the client specifically needs an older version, this will not work and may break backward compatibility. (80% 失败率)
