因此,我设置了一个应用程序以允许跨域请求。在这篇文章中使用了各种方法How to enable cross-origin resource sharing (CORS) in the express.js framework on node.jsCORS问题与节点
但是,我得到一个错误,我似乎无法理清。这是我正在使用的(不是我尝试了3种方法 - 他们都给出了相同的错误)。
app.use(function(req, res, next){
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Content-Type');
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
next();
})
.options('*', function(req, res, next){
res.end();
});
这仍然给我一个错误:
XMLHttpRequest cannot load http://localhost:3000/blah. Request header field Content-Type is not allowed by Access-Control-Allow-Headers.
如果我注释掉上面代码中,我得到预期不允许错误,似乎表明该请求是否正确由代码处理。我还重新输入了内容类型的请求,以确保我没有粘贴奇怪的字符。任何线索?