提问者:小点点

Safari中的访问控制源不允许源“http://localhost:8080


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

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

CORS错误

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

  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();
});
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个答案

匿名用户

从这个答案看来,在access-control-allow-headers中添加accept-language应该可以解决这个问题。