Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.
用的axios做的请求,express后端返回,post请求时报这个错
设置Axios.post('/api-user/login/login', params, {headers: {'sign': sign}}); 后面的sign时报
Request header field sign is not allowed by Access-Control-Allow-Headers in preflight response.
原因?求解
----------------------------------------------------------
let params={name:'hhl',psd:'123456'};
let out=Axios.get('/login',{params:params}); //格式不这么写就报 in preflight response
let out2=Axios.post('/login/abort', qs.stringify(params) ); //post需要用qs来转化一下
axios没有配置什么,express配置跨域
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",' 3.2.1');
res.header("Content-Type", "application/json;charset=utf-8");
next();
}
其中主要是origin,好像
问题已解决