# 错误：net/http：在10次重定向后停止

- **ID:** `go/net-http-client-does-not-follow-redirects`
- **领域:** go
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

HTTP客户端在达到默认的最大10次重定向后停止跟随，通常由于重定向循环。

## 版本兼容性

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

## 解决方案

1. **Set a custom CheckRedirect function to limit and log redirects** (90% 成功率)
   ```
   client := &http.Client{
    CheckRedirect: func(req *http.Request, via []*http.Request) error {
        if len(via) >= 5 { return http.ErrUseLastResponse }
        return nil
    },
}
   ```

## 无效尝试

- **Increasing CheckRedirect limit without fixing loop** — May cause infinite loop; fix the redirect logic. (60% 失败率)
