每次在不同机器上进行前后端交互都入坑,心想自己机器测都可以怎么连接的时候都连接不上,原来是每次自己的都忘记跨域请求!!!
特此记录下,以防再入坑!
跨域相关的两个header属性我都没有找到相关的定义,下面直接告诉大家
1是Access-Control-Allow-Origin 允许的域
2是Access-Control-Allow-Headers 允许的header类型
//设置跨域访问
app.all('*',function(req,res,next)
{
res.header("Access-Control-Allow-Origin","*");
res.header("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Content-Length,
Authorization, Accept,yourHeaderFeild");
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();
});