gpt4 book ai didi

google-app-engine - 如何在 Go App Engine Urlfetch 包中使用 Cookie

转载 作者:IT王子 更新时间:2023-10-29 01:59:56 26 4
gpt4 key购买 nike

此代码与常规 Go 代码一起工作正常。

cookieJar, err := cookiejar.New(nil)
// error handling
client := &http.Client{Jar: cookieJar}

// authenticate request
authUrl := "https://some_secure_site"
values := make(url.Values)
values.Set("login_email", "email")
values.Set("login_password", "password")
resp, err := client.PostForm(authUrl, values)
// handle error

// process resp

我需要使用 Go 在 App Engine 中执行类似的操作。 App Engine 使用 urlfetch 包而不是 http 包。

如何使用 urlfetch 包来执行此操作?

最佳答案

urlfetch.Client 返回一个 *http.Client

func Client(context appengine.Context) *http.Client

所以只需在创建的客户端中设置Jar

client := urlfetch.Client(c)
client.Jar = cookieJar
...

关于google-app-engine - 如何在 Go App Engine Urlfetch 包中使用 Cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25089083/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com