【发布时间】:2020-10-28 19:47:30
【问题描述】:
当我尝试使用邮递员访问端点时,一切正常,所以我认为问题可能出在我的 axios 请求上,因为在执行此 axios 请求后在服务器上记录 req.headers.cookies 时,值是 undefined。
浏览器中的 Cookie 也可以正常工作。
当我在邮递员中执行此请求时,req.headers.cookie 的值很好,并且请求已执行且没有任何错误。
客户端代码:
useEffect(() => {
(async () => {
const res = await axios.post('http://localhost:4000/refresh_token', {
withCredentials: true,
});
})();
}, []);
服务器代码(端点函数):
export const validateRefreshToken = async (req, res) => {
console.log(req.headers.cookie); // undefined
const { token } = parse(req.headers.cookie);
...
};
错误信息:TypeError argument str must be a string.
这个错误指向解析函数。
以前有人经历过吗?关于如何解决此问题的任何想法?
【问题讨论】:
标签: node.js reactjs express cookies axios