gpt4 book ai didi

java spark 框架无法设置或读取 cookie

转载 作者:行者123 更新时间:2023-11-30 06:50:31 25 4
gpt4 key购买 nike

我是 spark 框架的新手。当我尝试将 cookie 设置为响应或从请求中读取 cookie 时遇到问题。

路线:

post("/test/set/cookie", TestController.setCookie);
get("/test/get/cookie", TestController.getCookie);
post("/test/remove/cookie", TestController.removeCookie);

Controller :

public static Route setCookie = (Request request, Response response) -> {
System.out.println("set");
String id = UUID.randomUUID().toString();
response.cookie("test1", id, 3600, false, true);
return "done";
};

public static Route getCookie = (Request request, Response response) -> {
System.out.println("get");
String cookie = request.cookie("test1");
System.out.println(cookie);
return "done";
};

public static Route removeCookie = (Request request, Response response) -> {
System.out.println("remove");
response.removeCookie("test1");
return "done";
};

Postman set cookie

Postman get cookie faile

我错过了什么?

最佳答案

我终于解决了---

response.cookie("/", "test", "value", 3600, false, true);

只需要在cookie中添加路径"/"即可。

关于java spark 框架无法设置或读取 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41319853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com