go
config_error
ai_generated
true
错误:net/http:在10次重定向后停止
error: net/http: stopped after 10 redirects
ID: go/net-http-client-does-not-follow-redirects
80%修复率
84%置信度
0证据数
2025-09-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
根因分析
HTTP客户端在达到默认的最大10次重定向后停止跟随,通常由于重定向循环。
English
The HTTP client stopped following redirects after reaching the default maximum of 10 redirects, often due to a redirect loop.
解决方案
-
90% 成功率 Set a custom CheckRedirect function to limit and log redirects
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
60% 失败
May cause infinite loop; fix the redirect logic.