go cookie
Go 测试问题
-
cookie提示http: named cookie not present
- 在设置cookie之后,去获取同一本地的cookie内容时,提示named cookie not present错误
-
[code]
func setCookie(w http.ResponseWriter, r *http.Request) { expiration := time.Now().Add(time.Hour) http.SetCookie(w, &http.Cookie{ Name: "access_token", Value: "cookie get test", Expires: expiration, HttpOnly: true, }) redirectURL := "/" http.Redirect(w, r, redirectURL, 200) } func getCookie(w http.ResponseWriter, r *http.Request) { c, err := r.Cookie("access_token") if err != nil { fmt.Fprintf(w, "Cannot get the cookie %s", err) log.Fatal(err) } tokenString := c.Value fmt.Fprintln(w, tokenString) }
- 搜索相关问题,stackoverflow有相关说明:https://stackoverflow.com/questions/329364...
- 主要是与secure相关,带有secure:true的用户访问的cookie不会通过http发送cookies
- 将security设置为false后,使用chrom调用仍然不行,但在postman和其他浏览器是ok的,貌似与chrom的setting相关
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: