1.会发两次请求,也能访问返回结果,但是浏览器报错;2.浏览器报错No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.3.Content-Type:applycation/json;疑问:问什么允许访问还会报错
4 回答
慕桂英4014372
TA贡献1871条经验 获得超13个赞
exprss里是这么配置的,关键在于允许options请求以及options请求自动返回200
看你说的返回两次可能是因为post请求没达到简单请求的要求,会发送options
// cors跨域配置
app.all('*', function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With, Current-Page');
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
if (req.method == 'OPTIONS') {
res.sendStatus(200);
} else {
next();
}
});
添加回答
举报
0/150
提交
取消