dongyong8071 2018-02-07 16:52
浏览 92
已采纳

什么是命名cookie?

I am reading official documentation about Go language and found:

Cookie returns the named cookie provided in the request

When I try req.Cookie("My-Cookie") I receive named cookie not present

While when I fmt.Println(req.Cookies()) I receive following string:

[My-Cookie=a783e7e4-c331-4802-6544-7374f5128882 Path=/svc Expires="Tue, 07 Feb 2068 16:05:53 GMT" Path=/svc HttpOnly=]

What is the named cookie then?

  • 写回答

1条回答 默认 最新

  • dourang20110122 2018-02-08 19:36
    关注

    Here is a golang playground. It shows that what the OP posted works, so the bug is somewhere else. It also answers the question by showing what the named cookie is.

    package main
    
    import (
      "fmt"
      "net/http"
    )
    
    func main() {
      r := &http.Request{
        Header: http.Header{
          "Cookie": []string{
            "My-Cookie=a783e7e4-c331-4802-6544-7374f5128882 Path=/svc Expires=Tue, 07 Feb 2068 16:05:53 GMT Path=/svc HttpOnly=",
          },
        },
      }
    
      fmt.Println(r.Cookies())
    
      c, err := r.Cookie("My-Cookie")
      if err != nil {
        fmt.Println("Error:", err)
        return
      }
    
      // only cookie name and value are parsed
      fmt.Println("Name", c.Name)
      fmt.Println("Value", c.Value)
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!