最近开始尝试使用 golang 写一个小工具,在登陆网站的时候做了个 post 请求,但是返回的页面还是登陆页面,同样的参数用 postman 做 post ,得到的响应是登录成功后的页面,请问 postman 还做了什么处理吗?或者我这里还需要怎么操作
代码如下:
var reqBody = "username=" + number + "&password=" + url.QueryEscape(passwd)
client := &http.Client{}
req, err := http.NewRequest("POST", "https://****", strings.NewReader(reqBody))
if err != nil {
logSomething.LogError("failed to make a new request, err:%s", err)
return nil, 0, err
}
req.Header.Set("Host", "****")
req.Header.Set("Content-Length", strconv.Itoa(len(reqBody)))
req.Header.Set("Cache-Control", "max-age=0")
req.Header.Set("Sec-Ch-Ua", "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"96\", \"Google Chrome\";v=\"96\"")
req.Header.Set("Sec-Ch-Ua-Mobile", "?0")
req.Header.Set("Sec-Ch-Ua-Platform", "\"Windows\"")
req.Header.Set("Origin", "https://*****")
req.Header.Set("Upgrade-Insecure-Requests", "1")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36")
req.Header.Set("Accept", "text/html")
req.Header.Set("Sec-Fetch-Site", "same-origin")
req.Header.Set("Sec-Fetch-Mode", "navigate")
req.Header.Set("Sec-Fetch-User", "?1")
req.Header.Set("Sec-Fetch-Dest", "document")
req.Header.Set("Referer", "https://*****")
req.Header.Set("Accept-Encoding", "gzip")
req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9")
req.Header.Set("Connection", "close")
resp, err := client.Do(req)
if err != nil {
logSomething.LogError("failed to sent a new request, err:%s", err)
return nil, 0, err
}
defer resp.Body.Close()
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.