React不设置cookie,但Postman做到了吗?
我有一个弹簧引导后端,允许用户登录。
当我使用Postman发送JSON有效载荷以登录用户时,它会以cookie返回正确的响应以进行JSession。
当我在React(AXIOS)发送有效载荷时,我不会在任何地方都看到cookie的JSession,但回应还可以吗?
const API_URL = "http://localhost:8080/api/auth/";
login(uniqueId: string, password: string) {
return axios.post(API_URL + "login", JSON.stringify({
"uniqueId": uniqueId,
"password": password
}),
{
headers: {
'Content-Type': 'application/json',
'withCredentials': 'true'
}
})
.then(response => {
console.log(response);
return response;
}).catch(error => {
return error.response
});
}
I have a spring boot backend that allows a user to login.
When I use postman to send a json payload to login in a user it returns the correct response with a cookie for a JSESSION.
Postman details with response and cookie
When I send the payload in react (axios) I don't see the cookie for the JSESSION anywhere but the response is still okay ?
const API_URL = "http://localhost:8080/api/auth/";
login(uniqueId: string, password: string) {
return axios.post(API_URL + "login", JSON.stringify({
"uniqueId": uniqueId,
"password": password
}),
{
headers: {
'Content-Type': 'application/json',
'withCredentials': 'true'
}
})
.then(response => {
console.log(response);
return response;
}).catch(error => {
return error.response
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
'withCredentials':'true'
shoud在标题
(请求config documentStion )是:
另一个解决方案是使用参数
withCredentials创建实例轴:true
(创建axios实例)。然后您可以做:
'withCredentials': 'true'
shoud be outside ofheaders
(Request Config documentstion)In your case it would be:
another solution is create instance axios with parametr
withCredentials: true
(creating axios instance).and then you can do: