Home > other >  With the go cookiejar get cookies cannot enter
With the go cookiejar get cookies cannot enter

Time:09-21

With the go cookiejar cookie submitted cannot get into the page
The caught fidder but the cookie to get into the page
//HTTP request
UrlVal func httpHandle (method, the data string, client * HTTP client, the req. * the HTTP Request) {

//client:=& amp; . The HTTP Client {}
//var the req * HTTP Request

If data="https://bbs.csdn.net/topics/=" {
UrlArr:=strings. The Split (urlVal, "?" )
If len (urlArr)==2 {
UrlVal=urlArr [0] + "?" + getParseParam (urlArr [1])
}
The req, _=HTTP. NewRequest (method, urlVal, nil)
} else {
The req, _=HTTP. NewRequest (method, urlVal, strings. NewReader (data))
}

CookiesStr:="";
For _, v:=range client. The Jar. The Cookies (the req. URL) {
FMT. Println (" response header information - 222: ", v.N ame, "=", v.V alue)
CookiesStr +=v.N ame + "=" + v.V alue + "; "
}
FMT. Println (" cookiesStr="+ cookiesStr)

The 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 ")
The req. Header. The Set (" Accept - the Encoding ", "")
The req. Header. The Set (" cache-control ", "Max - age=0")
The req. Header. The Set (" Origin ", "http://www.xsjx8.com")
The req. Header. Set (" Accept - Language, "" useful - CN, useful; Q=0.9, en. Q=0.8 ")
The req. Header. Set (" the 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 ")
The req. Header. The Set (" Host ", "http://www.xsjx8.com")
The req. Header. The Set (" Connection ", "keep alive -")
The req. Header. The Set (" Upgrade - the Insecure - Requests ", "1")
The req. Header. The Set (" the content-type ", "application/x - WWW - form - urlencoded")
The req. Header. The Set (" Cookie ", cookiesStr) the caught fidder//but the Cookie to get into the page

Resp, err:=client. Do (the req)

if err ! Nil={
Println (" err=", err)
}
Defer resp. Body. The Close ()
B, _ :=ioutil ReadAll (resp. Body)
FMT. Println (string) (b)
}

CodePudding user response:

CookiesStr:="";
For _, v:=range client. The Jar. The Cookies (the req. URL) {
FMT. Println (" response header information - 222: ", v.N ame, "=", v.V alue)
CookiesStr +=v.N ame + "=" + v.V alue + "; "
the req. AddCookie (v) //add try here
}
  • Related