Gorilla 工具包的无限重定向循环
Infinite redirect loop with Gorilla toolkit
我有这个简单的代码:
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")
}
它在发出 GET 请求的行上冻结。它似乎进入了 302 响应的无限循环,重定向到相同的 url(“https://www.telegram.org”)。
我做错了还是假设错了?
感谢和问候。
显然该库不支持 https(笑)
https://github.com/gorilla/http/issues/8
所以只需使用 stdlib http 模块:
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)
}
我有这个简单的代码:
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")
}
它在发出 GET 请求的行上冻结。它似乎进入了 302 响应的无限循环,重定向到相同的 url(“https://www.telegram.org”)。 我做错了还是假设错了?
感谢和问候。
显然该库不支持 https(笑)
https://github.com/gorilla/http/issues/8
所以只需使用 stdlib http 模块:
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)
}