【问题】
折腾:
期间,使用如下代码:
var curCookies []http.Cookie = nil; curCookies = resp.Cookies
结果出错::
D:\tmp\tmp_dev_root\go\src\github.com\user\EmulateLoginBaidu>go run EmulateLoginBaidu.go # command-line-arguments .\EmulateLoginBaidu.go:64: cannot use resp.Cookies (type func() []*http.Cookie) as type []http.Cookie in assignment
如图:
即:
cannot use resp.Cookies (type func() []*http.Cookie) as type []http.Cookie in assignment |
【解决过程】
1. 再去改为:
var curCookies []http.Cookie = nil; curCookies = resp.Cookies()
结果是:
D:\tmp\tmp_dev_root\go\src\github.com\user\EmulateLoginBaidu>go run EmulateLoginBaidu.go # command-line-arguments .\EmulateLoginBaidu.go:64: cannot use resp.Cookies() (type []*http.Cookie) as type []http.Cookie in assignment
2.再去改为:
//var curCookies []http.Cookie = nil; //curCookies = resp.Cookies() var curCookies []*http.Cookie = nil; curCookies = resp.Cookies()
结果是:
可以了:
D:\tmp\tmp_dev_root\go\src\github.com\user\EmulateLoginBaidu>go run EmulateLoginBaidu.go # command-line-arguments .\EmulateLoginBaidu.go:66: curCookies declared and not used
剩下的,只是如何继续去使用这些Cookie了。
【总结】
此处,想要获得Http的Response的Cookies,做法是:
mport "net/http" var curCookies []*http.Cookie = nil; curCookies = resp.Cookies()
即可。
转载请注明:在路上 » 【已解决】go语言中想要获得Response的Cookies结果出错:cannot use resp.Cookies (type func() []*http.Cookie) as type []http.Cookie in assignment