duanchongchu5177 2016-01-31 04:27 采纳率: 0%
浏览 24
已采纳

大猩猩工具包的无限重定向循环

I have this simple code:

import (
   "log"
   "github.com/gorilla/http"
   "bytes"
)

func main() {
 url := "https://www.telegram.org"
 log.Println("url: " + url)
 var b bytes.Buffer
 http.Get(&b, url)
 log.Println("Get done")
}

and it freezes on the line making the GET request. It seems that it enters an infinite loop of 302 responses which redirects to the same url ("https://www.telegram.org"). Am I doing or assuming something wrong?

Thanks and regards.

  • 写回答

1条回答 默认 最新

  • dongzuozhu66776 2016-01-31 06:23
    关注

    Apparently that library doesn't support https (lol)

    https://github.com/gorilla/http/issues/8

    So just use the stdlib http module:

    package main
    
    import (
        "fmt"
        "io/ioutil"
        "net/http"
    )
    
    func main() {
    
        res, err := http.Get("https://www.telegram.org")
        if err != nil {
            return
        }
        defer res.Body.Close()
    
        body, err := ioutil.ReadAll(res.Body)
        if err != nil {
            return
        }
    
        fmt.Printf("%s", body)
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?