preflight response 应该是异步的什么问题---后来发现不是,是axios参数格式问题,网上其他一些解答太误导人了
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,好像
问题已解决
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步