dqbhdsec59405 2016-02-24 05:24
浏览 271

如何在Golang中查看cookieJar的内容?

I'm trying to view the contents of a cookieJar response from a request to google:

package main

import (
    "fmt"
    "log"
    "net/http"
    "net/http/cookiejar"
    "net/url"
)

func main() {

    jar, err := cookiejar.New(nil)
    if err != nil {
        log.Fatal(err)
    }
    client := http.Client{Jar: jar}
    resp, err := client.Get("https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Ffeature%3Dsign_in_button%26hl%3Den%26action_handle_signin%3Dtrue%26next%3D%252F%26app%3Ddesktop&service=youtube&sacu=1&passive=1209600&ignoreShadow=0&acui=0#identifier")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(resp.Cookies())

    s := ".google.com"
    u, err := url.Parse(s)
    fmt.Println(client.Jar.Cookies(u))

}

The response is a blank array but I can see that there are cookies being set. How do I view the contents of a cookieJar in Golang?

  • 写回答

1条回答 默认 最新

  • douyi9597 2016-02-24 06:41
    关注

    Unfortunately not, the cookie jar in the std library is completely opaque and can be queried via (non-wildcard) URLs only.

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)