首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Golang中设置Cookie(net/ HTTP)?

如何在Golang中设置Cookie(net/ HTTP)?

提问于 2018-04-24 07:02:17
回答 2关注 0查看 896

我试图用Golang的net / http设置cookie。我有

代码语言:javascript
复制
package main

import "io"
import "net/http"
import "time"

func indexHandler(w http.ResponseWriter, req *http.Request) {
    expire := time.Now().AddDate(0, 0, 1)
    cookie := http.Cookie{"test", "tcookie", "/", "www.domain.com", expire, expire.Format(time.UnixDate), 86400, true, true, "test=tcookie", []string{"test=tcookie"}}
    req.AddCookie(&cookie)
    io.WriteString(w, "Hello world!")
}

func main() {
    http.HandleFunc("/", indexHandler)
    http.ListenAndServe(":80", nil)
}

我试着用'cookies'搜索'Golang',但没有得到很好的解决方法。

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档