【发布时间】:2015-11-24 23:42:51
【问题描述】:
在执行 HTTP Get 请求时,我收到以下错误:
2015/08/30 16:42:09 Get https://en.wikipedia.org/wiki/List_of_S%26P_500_companies:
stopped after 10 redirects
在以下代码中:
package main
import (
"net/http"
"log"
)
func main() {
response, err := http.Get("https://en.wikipedia.org/wiki/List_of_S%26P_500_companies")
if err != nil {
log.Fatal(err)
}
}
我知道根据文档,
// Get issues a GET to the specified URL. If the response is one of
// the following redirect codes, Get follows the redirect, up to a
// maximum of 10 redirects:
//
// 301 (Moved Permanently)
// 302 (Found)
// 303 (See Other)
// 307 (Temporary Redirect)
//
// An error is returned if there were too many redirects or if there
// was an HTTP protocol error. A non-2xx response doesn't cause an
// error.
我希望有人知道这种情况下的解决方案是什么。这个简单的 url 导致十多个重定向似乎很奇怪。让我觉得幕后可能还有更多事情发生。
谢谢。
【问题讨论】:
-
如果你只是想解决这个问题,我建议更改http包源。
-
我觉得这里有些不对劲。该请求不仅可以从 telnet / curl 工作而无需单个重定向,而且您的示例程序(一旦我对响应做了一些事情)也可以在没有任何重定向的情况下工作。您是否正在通过某种代理,这就是导致重定向的原因?
-
使用 curl 可以吗?