【问题标题】:How to Use Cookies with Go App Engine Urlfetch Package如何在 Go App Engine Urlfetch 包中使用 Cookie
【发布时间】:2014-08-02 05:50:26
【问题描述】:

此代码适用于常规 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 包来做到这一点?

【问题讨论】:

    标签: google-app-engine cookies https go


    【解决方案1】:

    urlfetch.Client 返回一个*http.Client

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-04
      • 1970-01-01
      • 2011-01-10
      • 2010-12-30
      • 1970-01-01
      • 1970-01-01
      • 2011-02-03
      • 1970-01-01
      相关资源
      最近更新 更多