可以在前端使用cookie,但在邮递员中效果很好
我已经在Springboot中创建了REST API,该API在发送有效的凭据返回后,JWT访问令牌并保存在Httponly Cookie中的刷新令牌,当我将cookie在Postman中使用cookie的API发送时,它可以正常工作,但是当我尝试在React中获取React时, API返回错误,表明没有cookie
error_message:“无法读取数组长度,因为“数组”为null”
因此我必须指定域名,如果是,我在Localhost上工作时该如何执行(Springboot正在使用localhost:8080
and Code> and code>和React Localhost:3000
)。
我目前如何创建cookie:
public static Cookie createRefreshCookie(String refresh_token) {
Cookie jwtRefreshCookie = new Cookie("refresh_token", refresh_token);
jwtRefreshCookie.setMaxAge(2678400);
jwtRefreshCookie.setHttpOnly(true);
jwtRefreshCookie.setPath("/");
return jwtRefreshCookie;
}
I've created rest API in springboot that upon sending valid credentials returns jwt access token and saves refresh token in httpOnly cookie, when I send GET request to the API that uses cookie in postman it works just fine but when I try to fetch in react API returns error that indicates that there is no cookies
error_message: "Cannot read the array length because "array" is null"
So do I have to specify domain name If yes how do I do it while working on localhost (springboot is working on localhost:8080
and react localhost:3000
).
How I currently create cookie:
public static Cookie createRefreshCookie(String refresh_token) {
Cookie jwtRefreshCookie = new Cookie("refresh_token", refresh_token);
jwtRefreshCookie.setMaxAge(2678400);
jwtRefreshCookie.setHttpOnly(true);
jwtRefreshCookie.setPath("/");
return jwtRefreshCookie;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是由我在react中的提取请求造成的,该请求包含标头
withCredentials:true
来自库Axios的true axios insead forth fetter实现标题凭据:“ inclage”
。Problem was caused by my fetch request in react that contained header
withCredentials: true
from library axios insead of fetch implementation of headercredentials:"include"
.