我添加了标题以允许http删除,但是当我尝试删除(单击按钮)时,出现以下错误:
跨域请求被阻止:“同源起源”策略禁止读取http://localhost:5500/method处的远程资源。 (原因:CORS预检通道中的CORS标头Access-Control-Allow-Headers中缺少令牌access-control-allow-origin
let allowDelete = function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
next();
}
//和
router.options('/method', allowDelete);
router.delete('/method', functionT);
请求如下:
method(paramether: Paramether) {
return new Promise<boolean>( (resolve, reject) => {
this._http.delete<boolean>(Url, Option).subscribe( (res => {
resolve(res);
}));
});
}
你知道问题出在哪里吗?
答案 0 :(得分:-1)
您需要安装: npm install cors ,安装后,导入到app.js nodejs中 var cors = require('cors');