api
config_error
ai_generated
true
400 错误请求:API 版本标头 'X-API-Version' 是必需的,且必须为有效的语义化版本
400 Bad Request: API version header 'X-API-Version' is required and must be a valid semver
ID: api/rest-api-version-mismatch-header
95%修复率
86%置信度
1证据数
2024-05-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| REST API best practices 2023+ | active | — | — | — |
| Spring Boot 3.x | active | — | — | — |
| FastAPI 0.100+ | active | — | — | — |
| Express.js 4.x | active | — | — | — |
根因分析
客户端未在请求中包含必需的 'X-API-Version' 标头,或者该值不符合语义化版本控制(例如,'2.0' 而非 '2.0.0')。
English
The client did not include the required 'X-API-Version' header in the request, or the value does not conform to semantic versioning (e.g., '2.0' instead of '2.0.0').
官方文档
https://semver.org/解决方案
-
Add the 'X-API-Version' header with a valid semver value. Example in cURL: curl -H 'X-API-Version: 2.0.0' https://api.example.com/resource
-
Check the API documentation for the exact version string required (e.g., '1.0.0', '2.1.3').
-
If using an HTTP client library, set default headers. Example in Python requests: headers = {'X-API-Version': '2.0.0'} response = requests.get('https://api.example.com/resource', headers=headers)
无效尝试
常见但无效的做法:
-
90% 失败
The server strictly requires the header; omitting it results in a 400 error.
-
70% 失败
The server expects a full semver string (e.g., '2.0.0'); partial versions are rejected.
-
95% 失败
The server specifically looks for 'X-API-Version'; other headers are ignored.