GoSDK操作Cookie
1.介绍
2.Cookie结构体
3.简单案例
package main
import (
"fmt"
"net/http"
)
func Handle(w http.ResponseWriter, r *http.Request) {
c, err := r.Cookie("sessionid")//获取cookie的第一种方法
fmt.Println(c, err)
cookie := &http.Cookie{
Name: "sessionid",
Value: "lkjsdfklsjfklsfdsfdjslf",
MaxAge: -1,
Domain: "localhost",
Path: "/",
}
if err != nil {
http.SetCookie(w, cookie)
}
}
func main() {
http.HandleFunc("/hello", Handle)
http.ListenAndServe(":9090", nil)
}
/*
*func SetCookie(w ResponseWriter, cookie *Cookie) {}
*func (r *Request) Cookie(name string) (*Cookie, error) {}
*/
第一次搜索浏览器
第二次搜索浏览器