Ai
1 Star 0 Fork 3

源码大数据(codebigdata)/goWebActualCombat

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
3.4-cookie1.go 546 Bytes
一键复制 编辑 原始数据 按行查看 历史
ShirDon-廖显东 提交于 2021-01-19 21:02 +08:00 . commit
package main
import (
"fmt"
"net/http"
)
func testHandle(w http.ResponseWriter, r *http.Request) {
c, err := r.Cookie("test_cookie")
fmt.Printf("cookie:%#v, err:%v\n", c, err)
cookie := &http.Cookie{
Name: "test_cookie",
Value: "krrsklHhefUUUFSSKLAkaLlJGGQEXZLJP",
MaxAge: 3600,
Domain: "localhost",
Path: "/",
}
http.SetCookie(w, cookie)
//在具体数据返回之前设置cookie,否则cookie种不上
w.Write([]byte("hello"))
}
func main() {
http.HandleFunc("/", testHandle)
http.ListenAndServe(":8085", nil)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/codebigdata/goWebActualCombat.git
git@gitee.com:codebigdata/goWebActualCombat.git
codebigdata
goWebActualCombat
goWebActualCombat
b84124f40e18

搜索帮助