简体   繁体   English

Chrome是否会更改Access-Control-Allow-Origin?

[英]Does Chrome changes Access-Control-Allow-Origin?

Browsing with Chrome to my nodejs web site. 使用Chrome浏览我的nodejs网站。 The Access-Control-Allow-Origin value that I see in Chrome developers tools is different from the one that I define in my nodejs 我在Chrome开发人员工具中看到的Access-Control-Allow-Origin值与我在nodejs中定义的值不同

In my nodejs 在我的nodejs中

res.setHeader('Access-Control-Allow-Origin', "siteA");

When I look at the Chrome developers tools under Network -> Response Headers I see 当我查看网络 - >响应标题下的Chrome开发人员工具时,我看到了

Access-Control-Allow-Origin: siteB

Tried with Edge - working fine 尝试边缘 - 工作正常

I clean the site data using Application->clean storage - didn't help 我使用Application-> clean storage清理站点数据 - 没有帮助

The error code I get in chrome is 我在chrome中得到的错误代码是

Access to XMLHttpRequest at 'XXXXX' from origin 'siteA' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header has a value 'siteB' that is not equal to the supplied origin.

Can you please change res.setHeader('Access-Control-Allow-Origin', "siteA"); 你能否改变res.setHeader('Access-Control-Allow-Origin', "siteA"); to res.setHeader('Access-Control-Allow-Origin', "*"); res.setHeader('Access-Control-Allow-Origin', "*");

 app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Methods","POST","GET")
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type,authorization,Accept");

  res.header('Access-Control-Allow-Credentials', 'true'); 
  next();
});  

Please copy and paste this code in your servers index.js file.I think this should work. 请将此代码复制并粘贴到您的服务器index.js文件中。我认为这应该有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM