【发布时间】:2022-06-16 00:42:57
【问题描述】:
我需要使用golang登录我的openwrt路由器后端,登录返回不是cookie而是302页面重定向,如果直接发送请求将触发403,我也在http调试工具上调试,我需要禁止重定向到在返回标头中获取cookie值,如果默认他将显示403,如果我不允许重定向将显示302,那么,当我使用net / http发送请求时有没有办法禁用重定向
:)
func login() {
rq, _ := http.NewRequest("POST", "http://10.0.0.1/cgi-bin/luci/", strings.NewReader("luci_username=root&luci_password=password"))
rq.Header.Add("Content-Type", "application/x-www-form-urlencoded")
rs, _ := http.DefaultClient.Do(rq)
// out, _ := ioutil.ReadAll(rs.Body)
out := rs.Header
fmt.Printf("%s", out)
}
【问题讨论】:
-
在
http.Client上使用CheckRedirect:pkg.go.dev/net/http#Client