用go cookiejar 得到的cookie 提交无法进入
用go cookiejar 得到的cookie 提交无法进入页面
但用抓包fidder得到的cookie 就可以进入页面
//http请求
func httpHandle(method, urlVal,data string,client *http.Client, req *http.Request) {
//client := &http.Client{}
//var req *http.Request
if data == "" {
urlArr := strings.Split(urlVal,"?")
if len(urlArr) == 2 {
urlVal = urlArr[0] + "?" + getParseParam(urlArr[1])
}
req, _ = http.NewRequest(method, urlVal, nil)
}else {
req, _ = http.NewRequest(method, urlVal, strings.NewReader(data))
}
cookiesStr := "";
for _,v := range client.Jar.Cookies(req.URL){
fmt.Println("响应头信息-222 :",v.Name,"=",v.Value)
cookiesStr += v.Name+"="+v.Value+"; "
}
fmt.Println("cookiesStr = "+cookiesStr)
req.Header.Set("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
req.Header.Set("Accept-Encoding","")
req.Header.Set("Cache-Control","max-age=0")
req.Header.Set("Origin","http://www.xsjx8.com")
req.Header.Set("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8")
req.Header.Set("User-Agent","Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36")
req.Header.Set("Host","http://www.xsjx8.com")
req.Header.Set("Connection","keep-alive")
req.Header.Set("Upgrade-Insecure-Requests","1")
req.Header.Set("Content-Type","application/x-www-form-urlencoded")
req.Header.Set("Cookie",cookiesStr) //但用抓包fidder得到的cookie 就可以进入页面
resp, err := client.Do(req)
if err != nil {
println("err = ",err)
}
defer resp.Body.Close()
b, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(b))
}