Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有获取cookie的接口吗 #257

Open
xuyang404 opened this issue Aug 26, 2020 · 10 comments
Open

有获取cookie的接口吗 #257

xuyang404 opened this issue Aug 26, 2020 · 10 comments

Comments

@xuyang404
Copy link

如题,有获取cookie的接口吗

@guonaihong
Copy link
Owner

是要自动管理服务端生成的cookie?

@guonaihong
Copy link
Owner

如果是,可以看下下面的代码

      jar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
        if err != nil {
                log.Fatal(err)
        }

        client := &http.Client{
                Jar: jar,
        }

        gout.New(client).GET(ts.URL).SetBody("hi cookie").Do()
        gout.New(client).GET(ts.URL).SetBody("hi cookie2").Do() //抓下包就可以看到自动持有服务端一开始设置的cookie了。

@xuyang404
Copy link
Author

但是我需要保存服务端设置的cookie到本地,以供别的程序做模拟登录用

@guonaihong
Copy link
Owner

guonaihong commented Aug 26, 2020

可以通过BindHeader获取cookie的值。

type rspHeader struct {
    SetCookie string `header:"Set-Cookie"`
}
var header rspHeader
gout.New().GET(ts.URL).SetBody("hi cookie").BindHeader(&header).Do()
fmt.Printf("cookie value:%v\n", header)

@xuyang404
Copy link
Author

好的,感谢

@guonaihong
Copy link
Owner

ok

@bequt
Copy link

bequt commented Apr 8, 2022

ok

如何用网页端的raw版cookie直接设置到请求中? 同样也是模拟登录,
谢谢.

@bequt
Copy link

bequt commented Apr 8, 2022

类似这种cookie

BIDUPSID=0B7318C9F5F65A594B3153411C68E456; PSTM=1649431770; BAIDUID=0B7318C9F5F65A59B8A6EFA1ABDB0B12:FG=1; BD_HOME=1; BD_UPN=12314753; H_PS_PSSID=36159_31660_36087_36166_34584_36140_36120_35978_35822_36236_26350_35724_22160_36061; BA_HECTOR=0h208k8h2h2k01009r1h50l740r

@bequt
Copy link

bequt commented Apr 8, 2022

抱歉懂了, 从python转过来突然有点不适应, 如果不懂朋友, 可以直接把rawcookie直接设置到headers上即可.

浏览器 cookie

@guonaihong
Copy link
Owner

@bequt 欢迎进入go的世界. 有时间也可以一起完善gout的文档.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants