【问题标题】:Origin 'http://localhost:8080' is not allowed by Access Control Origin in SafariSafari 中的访问控制来源不允许来源“http://localhost:8080”
【发布时间】:2020-11-13 07:23:36
【问题描述】:

对于我正在运行的 Angular 10 应用程序,当页面在 Safari 中加载时出现以下错误。 (适用于 Chrome 和 Firefox)。

Origin http://localhost:8080 is not allowed by Access-Control_origin

CORS Error

我已尝试以下解决方案来解决此问题。但它们似乎都不起作用。

  1. server.ts 中,我将标题设置如下:-
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});
  1. 我还尝试了以下方法:-
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
  next();
});
  1. 我也尝试过,通过清除浏览器缓存和 cookie。

这些似乎都不起作用。 谁能帮我解决这个问题?

  1. 列表项

【问题讨论】:

  • 你可以使用这个example here。它会解决你的问题!

标签: node.js cors angular10


【解决方案1】:

that answer看来,在Access-Control-Allow-Headers中添加Accept-Language应该可以解决问题。

【讨论】:

  • 我试过这个。 res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept-Language, Accept"); 好像不行。 :(
猜你喜欢
  • 2014-07-30
  • 1970-01-01
  • 2017-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-11
相关资源
最近更新 更多