怎么获取响应头和Cookie?
ShineJstar opened this issue · comments
我要做个爬虫模拟登陆,要怎么获取响应和Cookie,查了所有函数都不能方便获取,只能通过Bind(req *http.Request, resp *http.Response)函数太复杂了。
解析响应头里面的Set-Cookie
字段,是否是你需要的方法?
type RspHeader struct {
Cookie string `header:"Set-Cookie"`
}
func main() {
var header RspHeader
err := gout.GET("localhost:8080").
BindHeader(&header).
Do()
fmt.Println(header)
谢谢,这样也可以,如果有BindCookie能取出[]http.Cookie就更好了,SetCookies也就能直接用了。
这样取出的cookie只有一个,用[]string能取出多个cookie,但SetHeader(core.H{"Cookie": header.Cookie})在请求时候序列化成json数组了,服务端识别不了cookie了,转[]http.cookie来解决又增加麻烦性了
我想下,有没有更好的方法。
…---原始邮件---
发件人: "ShineJstar"<notifications@github.com>
发送时间: 2021年2月2日(周二) 晚上9:01
收件人: "guonaihong/gout"<gout@noreply.github.com>;
抄送: "guonaihong"<guonaihong@qq.com>;"Comment"<comment@noreply.github.com>;
主题: Re: [guonaihong/gout] 怎么获取响应头和Cookie? (#270)
这样取出的cookie只有一个,用[]string能取出多个cookie,但SetHeader(core.H{"Cookie": header.Cookie})在请求时候序列化成json数组了,服务端识别不了cookie了,转[]http.cookie来解决又增加麻烦性了
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
你现在需求是自动管理服务端返回的cookie?
…---原始邮件---
发件人: "ShineJstar"<notifications@github.com>
发送时间: 2021年2月2日(周二) 晚上9:01
收件人: "guonaihong/gout"<gout@noreply.github.com>;
抄送: "guonaihong"<guonaihong@qq.com>;"Comment"<comment@noreply.github.com>;
主题: Re: [guonaihong/gout] 怎么获取响应头和Cookie? (#270)
这样取出的cookie只有一个,用[]string能取出多个cookie,但SetHeader(core.H{"Cookie": header.Cookie})在请求时候序列化成json数组了,服务端识别不了cookie了,转[]http.cookie来解决又增加麻烦性了
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
看下#219 能否解决你的问题。
…---原始邮件---
发件人: "ShineJstar"<notifications@github.com>
发送时间: 2021年2月2日(周二) 晚上9:01
收件人: "guonaihong/gout"<gout@noreply.github.com>;
抄送: "guonaihong"<guonaihong@qq.com>;"Comment"<comment@noreply.github.com>;
主题: Re: [guonaihong/gout] 怎么获取响应头和Cookie? (#270)
这样取出的cookie只有一个,用[]string能取出多个cookie,但SetHeader(core.H{"Cookie": header.Cookie})在请求时候序列化成json数组了,服务端识别不了cookie了,转[]http.cookie来解决又增加麻烦性了
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
非常棒,现在完美解决我的问题了,感谢 :)
ok。哈哈
…---原始邮件---
发件人: "ShineJstar"<notifications@github.com>
发送时间: 2021年2月3日(周三) 上午10:28
收件人: "guonaihong/gout"<gout@noreply.github.com>;
抄送: "guonaihong"<guonaihong@qq.com>;"Comment"<comment@noreply.github.com>;
主题: Re: [guonaihong/gout] 怎么获取响应头和Cookie? (#270)
非常棒,现在完美解决我的问题了,感谢 :)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
thx :)