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)
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function