从Springboot应用程序发送的Cookie无法存储在浏览器中。 “Set-Cookie”标头存在,但 devtools->application->cookie 选项卡为空

问题描述 投票:0回答:0

Springboot 后端 -> 发送带有令牌的 Cookie 作为响应 enter image description here

React 前端 -> Cookie 存在于响应标头中。 enter image description here enter image description here

但是浏览器不存储 Cookie。应用程序 -> Cookie 选项卡为空。

因此,从 React 应用程序向后端 API 发出的请求会收到 401 未经授权的请求,因为后续请求中不存在 Cookie 中的令牌。

邮递员的测试工作绝对正常。 enter image description here

我正在寻找一种解决方案来解决该问题,并在请求时成功将 Cookie 存储在浏览器应用程序选项卡中,以便 React 应用程序可以使用 cookie 向后端发出后续请求,而不会出现 401 未经授权的错误。

P.s.-我知道我可以将 jwt 令牌存储在本地存储中,但这是不安全的,我只想通过后端 Cookie(httpOnly)发送它

reactjs spring-boot cookies httpresponse setcookie
© www.soinside.com 2019 - 2024. All rights reserved.