# http：请求体过大

- **ID:** `go/http-request-body-too-large`
- **领域:** go
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

传入的HTTP请求体超过服务器允许的最大大小，通常是由于缺少MaxBytesReader或服务器配置所致。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.19 | active | — | — |
| 1.20 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   r.Body = http.MaxBytesReader(w, r.Body, 10<<20) // 10 MB limit
   ```
2. **** (80% 成功率)
   ```
   if r.ContentLength > maxSize {
    http.Error(w, "Request body too large", http.StatusRequestEntityTooLarge)
    return
}
   ```

## 无效尝试

- **** — ReadBufferSize is not related to body size limits and will not prevent the error. (90% 失败率)
- **** — Simply increasing the limit may allow denial-of-service attacks. (50% 失败率)
