Node.js 飞行前响应中访问控制允许标头中的允许请求标头字段
我尝试axios调用外部域: (get call返回有关邮政编码的任何信息) 在前端,我使用:Node.js 飞行前响应中访问控制允许标头中的允许请求标头字段,node.js,express,header,cors,axios,Node.js,Express,Header,Cors,Axios,我尝试axios调用外部域: (get call返回有关邮政编码的任何信息) 在前端,我使用: axios:v0.17.1 vue:v2.5.3 网页:3.6.0 在后端,我使用expressjs/nodejs并安装expresscors来处理这种情况 节点9.8.0 快报4.15.2 cors 2.8.4 我需要弄清楚如何在飞行前响应中允许Access-Control_allow-Headers中的Request header字段授权正常工作 我正在本地开发主机:8021 授权是具有我
- axios:v0.17.1
- vue:v2.5.3
- 网页:3.6.0
- 节点9.8.0
- 快报4.15.2
- cors 2.8.4
var corsOptions = {
origin: true,
allowedHeaders: ['Content-Type', 'authorization', 'Content-Length', 'X-Requested-With', 'Accept'],
exposedHeaders: ['authorization'],
methods: ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS'],
// optionsSuccessStatus: 204, // some legacy browsers (IE11, various SmartTVs) choke on 204
preflightContinue: false
}
app.use(cors(corsOptions))
但它无论如何都不起作用=(试试:
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
res.header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, PATCH, OPTIONS');
可能重复和否,因为我尝试了它,但不起作用。app.use(函数(req,res,next){//res.header('Access-Control-Allow-Origin','),”//res.header('Access-Control-Allow-Methods','GET,PUT,POST,DELETE,OPTIONS')console.log('vou fazer');res.header('Access-Control-Allow-Headers','authorization,vai-tomar-No-cu');next())
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
res.header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, PATCH, OPTIONS');