# http: 请求体已关闭

- **ID:** `go/http-request-body-already-closed`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

尝试读取或关闭已经关闭的http.Request.Body，通常是由于重复关闭或处理器返回后继续读取。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.21 | active | — | — |
| 1.22 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   if body, err := io.ReadAll(r.Body); err == nil { r.Body.Close() }
   ```
2. **** (90% 成功率)
   ```
   defer r.Body.Close() once at start of handler
   ```

## 无效尝试

- **** — Silently ignoring leads to incomplete reads and potential data corruption (80% 失败率)
- **** — Request body is a stream and cannot be reopened; must be buffered upfront if multiple reads needed (90% 失败率)
