Last active
August 25, 2017 08:18
-
-
Save magicianShiro/2a8a5089c5a817b7a4dafbbfd0a258bf to your computer and use it in GitHub Desktop.
使用rest风格发送请求, 跨域时关于服务器端的设置
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 设置请求头来实现跨域, 允许请求头和方法 | |
app.use((req, res, next) => { | |
res.header("Access-Control-Allow-Origin", "*") | |
res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With") | |
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS") | |
next() | |
}) | |
// 设置前端可以从响应头中获取那些信息 | |
Access-Control-Expose-Headers : '要获取的响应头中的舰值' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment