get cookies is array from editThisCookie
twolao opened this issue · 7 comments
how to use SetCookies() ?
error msg : cannot use cookies (variable of type []*http.Cookie) as type *http.Cookie in argument to handle.SetCookies
Can you send your code ?
original example cookies string, how to use gout?
[ { "domain": ".mail.163.com", "hostOnly": false, "httpOnly": false, "name": "starttime", "path": "/", "sameSite": "unspecified", "secure": false, "session": true, "storeId": "0", "value": "", "id": 1 }, { "domain": "mail.163.com", "expirationDate": 1668821546, "hostOnly": true, "httpOnly": false, "name": "gdxidpyhxdE", "path": "/", "sameSite": "unspecified", "secure": false, "session": false, "storeId": "0", "value": "l57OOfVtggWxCyktw5d1QHL42REEqPhLhOOEvsdh7tCPO5VrJ7LyA2X9%2BdLgOT%2B3bMd%5CN2hKsNTleanZHs0lNjmY3%5Cj1xmnWQPjIJUswn9oDsp3HvVVvrSLl%2FeQnzz2Lx0W0OLInwQhkIgem6KVPGR7qZ2LJ8ZH8wVzZmLfe03XHodBf%3A1666229546415", "id": 2 }, { "domain": "mail.163.com", "hostOnly": true, "httpOnly": false, "name": "stats_session_id", "path": "/", "sameSite": "unspecified", "secure": false, "session": true, "storeId": "0", "value": "ece4446d-f58c-4844-af01-2c06e301d549", "id": 3 } ]
Can you send your code ?
`package main
import (
"fmt"
"net/http"
"github.com/json-iterator/go"
"github.com/guonaihong/gout"
"github.com/guonaihong/gout/debug"
)
var json = jsoniter.ConfigFastest
var cookieStr = [ { "domain": ".mail.163.com", "hostOnly": false, "httpOnly": false, "name": "starttime", "path": "/", "sameSite": "unspecified", "secure": false, "session": true, "storeId": "0", "value": "", "id": 1 }, { "domain": "mail.163.com", "expirationDate": 1668821546, "hostOnly": true, "httpOnly": false, "name": "gdxidpyhxdE", "path": "/", "sameSite": "unspecified", "secure": false, "session": false, "storeId": "0", "value": "l57OOfVtggWxCyktw5d1QHL42REEqPhLhOOEvsdh7tCPO5VrJ7LyA2X9%2BdLgOT%2B3bMd%5CN2hKsNTleanZHs0lNjmY3%5Cj1xmnWQPjIJUswn9oDsp3HvVVvrSLl%2FeQnzz2Lx0W0OLInwQhkIgem6KVPGR7qZ2LJ8ZH8wVzZmLfe03XHodBf%3A1666229546415", "id": 2 }, { "domain": "mail.163.com", "hostOnly": true, "httpOnly": false, "name": "stats_session_id", "path": "/", "sameSite": "unspecified", "secure": false, "session": true, "storeId": "0", "value": "ece4446d-f58c-4844-af01-2c06e301d549", "id": 3 } ]
func main() {
var cookies []*http.Cookie
err := json.Unmarshal([]byte(cookieStr), &cookies)
if err != nil {
fmt.Println(err)
}
s := ""
handler := gout.GET("https://httpbin.org/headers")
//SetHeader(gout.H{"User-Agent": "hello"}).
handler = handler.Debug(debug.Trace()).BindBody(&s)
handler = handler.SetCookies(cookies)
err = handler.Do()
fmt.Printf("err:%e\n", err)
fmt.Printf(s)
}`
See if #219 can solve your problem.
how to use SetCookies() ?
error msg : cannot use cookies (variable of type []*http.Cookie) as type *http.Cookie in argument to handle.SetCookies
For the error code here, just put this line
handler = handler.SetCookies(cookies)
Modify according to the following code example
handler = handler.SetCookies(cookies...)
看下 #219 这个能否解决你的问题。
thanx, or can be used like this
for _, v := range cookies {
handler = handler.SetCookies(v)
}
how to use SetCookies() ?
error msg : cannot use cookies (variable of type []*http.Cookie) as type *http.Cookie in argument to handle.SetCookies这里的错误,只要把这一行
handler = handler.SetCookies(cookies)修改为如下就行
handler = handler.SetCookies(cookies...)
ok