猿问

维基百科网址在 10 次重定向错误 GoLang 后停止

执行 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 导致十多个重定向似乎很奇怪。让我觉得在幕后可能还有更多事情发生。


神不在的星期二
浏览 193回答 2
2回答

守着星空守着你

我在包含 Wikipedia URL 时遇到了这个问题,%26因为它们重定向到一个 URL 版本,&然后 Go 将其编码为%26Wikipedia 重定向到的 URL&和......奇怪的是,gcc-go从我的 Arch 盒子中移除(v1.4) 并用go(v1.5)替换它已经解决了这个问题。我猜这可以归结为net/httpv1.4 和 v1.5 之间的变化。
随时随地看视频慕课网APP

相关分类

Go
我要回答