当前位置:   article > 正文

Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight respon_cors policy: request header field content-type is

cors policy: request header field content-type is not allowed by access-cont

Access to fetch at ‘http://localhost:3000/books/231’ from origin ‘http://127.0.0.1:5500’ has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

// 设置允许跨域访问该服务
app.all('*', function (req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header('Access-Control-Allow-Credentials', 'true');
  res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  res.header('Access-Control-Allow-Headers', 'Content-Type');
  res.header('Access-Control-Allow-Headers', 'mytoken');
  next();
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

在网上找了挺多最后解决方法是
加了一句
用于判断request来自ajax还是传统请求

 res.header("Access-Control-Allow-Headers", " Origin, X-Requested-With, Content-Type, Accept");
  • 1

解决发送post请求时跨域无法访问

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/63692
推荐阅读
相关标签
  

闽ICP备14008679号