# 错误：http：响应体过大

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

## 根因

HTTP响应体超过允许的最大大小，通常由于服务器发送大量数据而未设置适当限制。

## 版本兼容性

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

## 解决方案

1. **Use io.LimitReader to cap response size** (95% 成功率)
   ```
   maxSize := int64(10 << 20) // 10 MB
body, err := io.ReadAll(io.LimitReader(resp.Body, maxSize))
if err != nil { return err }
if int64(len(body)) == maxSize { /* handle truncation */ }
   ```

## 无效尝试

- **Reading entire body into memory** — May cause out-of-memory; use io.LimitReader. (80% 失败率)
