通知短信+运营短信,5秒速达,支持群发助手一键发送🚀高效触达和通知客户 广告
### Cookies Cookie 是用户在访问网站时服务器发送过来存储在浏览器上的一小段数据。每次用户访问网页,浏览器都把 Cookies 发送回服务器以提醒服务器这个用户以前干过什么。 Cookie 用来提供一个可靠的途径让服务器记住一些状态信息(比如在线商城中添加物品到购物车)或者记录用户的浏览器行为(比如点击了某个按钮,登录,哪个页面被访问过)。 Cookie 也可以用来存储用户输入过的表单内容像电话号码,地址等等。 Cookie 属性 | 属性 | 可选 | | --- | --- | | Name | No | | Value | No | | Path | Yes | | Domain | Yes | | Expires |Yes | | Secure | Yes | | HTTPOnly | Yes | 创建一个 Cookie: ~~~ func SimpleCookie(ctx dotweb.Context) error { ctx.SetCookieValue("test", "val", 1000) return nil } func WriteCookie(ctx dotweb.Context) error { cookie := &http.Cookie{Name: "test", Value: url.QueryEscape("val"), MaxAge: 1000, HttpOnly: true} ctx.SetCookie(cookie) return nil } ~~~ 读取 Cookie: ~~~ func ReadCookie(ctx dotweb.Context) error { cookie, err:=ctx.ReadCookie("test") if err != nil { return err } fmt.Println(cookie.Name) fmt.Println(cookie.Value) ctx.WriteString("read a cookie") return nil } ~~~