小编Mat*_*att的帖子

axios 不检索 cookie

嘿,我遇到了一个问题,当我在本地运行服务器和应用程序时没有问题,但是当每个服务器和应用程序被推送到各自的服务器时,应用程序不会返回 cookie。有谁知道如何解决这个问题?

服务器:

app.use(function(req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Credentials', true);
  res.header(
    'Access-Control-Allow-Headers',
    'Origin, X-Requested-With, Content-Type, Accept'
  );
  next();
});
Run Code Online (Sandbox Code Playgroud)

反应:

const request = axios.post(`${url}/api/login`, {
      email,
      password,
      withCredentials: true,
      headers: { crossDomain: true, 'Content-Type': 'application/json' },
    })
    .then(response => response.data);
Run Code Online (Sandbox Code Playgroud)

node.js cors reactjs

3
推荐指数
1
解决办法
9536
查看次数

标签 统计

cors ×1

node.js ×1

reactjs ×1