对于我正在运行的一个Angular 10应用程序,当页面加载到Safari中时,会出现以下错误。 (适用于Chrome和Firefox)。
Origin http://localhost:8080 is not allowed by Access-Control_origin
CORS错误
我尝试了以下解决方案来解决这个问题。 但它们似乎都不起作用。
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();
});
这些似乎都不起作用。 谁能帮我这个忙吗?
从这个答案看来,在access-control-allow-headers
中添加accept-language
应该可以解决这个问题。