# FastAPI 请求验证错误：缺少请求体，字段必填。

- **ID:** `python/fastapi-missing-body`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

请求体是必需的但未发送。这通常发生在 POST 请求没有发送请求体或 Content-Type 错误时。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **Send a valid JSON body with required fields** (95% 成功率)
   ```
   curl -X POST http://localhost:8000/items -H 'Content-Type: application/json' -d '{"name": "item"}'
   ```
2. **Make the body optional in the endpoint** (90% 成功率)
   ```
   from fastapi import Body
@app.post('/items')
def create_item(data: dict = Body(None)):
    return data
   ```

## 无效尝试

- **Setting Content-Type to text/plain** — FastAPI expects JSON by default. (80% 失败率)
- **Sending an empty body** — Empty body is still missing required fields. (90% 失败率)
