Go web开发:浏览器可以';不定形饼干

Go web开发:浏览器可以';不定形饼干,go,web,Go,Web,我想在Go中设置cookie: func rememberMe(w http.ResponseWriter,username string) { expiration := time.Now().AddDate(0,1,0) // cookie will be stored for 1 month cookie := http.Cookie{Name: "rememberMe",Value: username,Expires: expiration} http.SetCo

我想在Go中设置cookie:

func rememberMe(w http.ResponseWriter,username string) {
    expiration := time.Now().AddDate(0,1,0) // cookie will be stored for 1 month
    cookie := http.Cookie{Name: "rememberMe",Value: username,Expires: expiration}
    http.SetCookie(w,&cookie)
    fmt.Println("Cookie has been set.")
}
响应很好,有一个设置Cookie字段:

Access-Control-Allow-Headers: Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE
Access-Control-Allow-Origin: *
Content-Length: 10
Content-Type: text/plain; charset=utf-8
Date: Thu, 20 Sep 2018 12:48:20 GMT
Set-Cookie: rememberMe=buddy; Expires=Sat, 20 Oct 2018 12:48:19 GMT

但是当我使用Chrome开发者工具检查cookie时,没有cookie。我对这个问题感到困惑
谢谢@Peter。我的后端运行在localhost:8088,前端运行在localhost:8080。所以我在后端和前端都做了一些配置。以下是后端代码:

func SetupResponse(w *http.ResponseWriter, r *http.Request) {
    (*w).Header().Set("Access-Control-Allow-Origin", "http://localhost:8080")
    (*w).Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
    (*w).Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
    (*w).Header().Set("Access-Control-Allow-Credentials", "true")
}
我在前端使用axios:

this.$axios.create({ withCredentials: true })
.get("http://localhost:8088/api/")
.then((response) => {
//....
}).catch((error) => {
  console.log(error);
});

我刚试过,饼干就做好了。您是否查看了应用程序/存储/Cookies下的开发人员工具?如果默认路径不够好,请不要忘记设置路径。浏览器是否会在后续请求时将cookie发送回服务器?我确实在Application/Storage/Cookies下检查了cookie,但没有任何内容。@mbuechmann这是跨源请求吗?如果是这样,请不要忘记在客户端上启用withCredentials并从服务器发送访问控制允许凭据:true:否,浏览器在后续请求时未发送任何cookie。设置路径的确切含义是什么?“我是一名新的web开发人员,我不能理解这一点。”沃尔克说