2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > Response to preflight request doesn‘t pass access control check: It does not have HTTP ok status

Response to preflight request doesn‘t pass access control check: It does not have HTTP ok status

时间:2020-09-18 03:11:33

相关推荐

Response to preflight request doesn‘t pass access control check: It does not have HTTP ok status

报错图片

答案:

app.all('*', function(req, res, next) {res.header('Access-Control-Allow-Origin', ':3000');res.header('Access-Control-Allow-Methods', 'HEAD, GET, POST, PUT, DELETE, OPTIONS');res.header('Access-Control-Allow-Headers', 'Content-Type, X-Requested-With, Origin, Accept');res.header('Access-Control-Allow-Credentials', 'true');if (req.method.toLowerCase() === 'options') {res.send(200);} else {next();}});

原因 :

如图显示,会优先请求OPTIONS方法,假如这时候没有返回200

这时候不会发出PSOT请求

所以这时候后端更改为在处理登录 url 时不需要对OPTIONS方法进行身份验证。

相关链接

1.stack overflow

2. GitHub

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。