Ajax Request header field Key is not allowed by Access-Control-Allow-Headers

删除回忆录丶 提交于 2019-12-03 00:31:31

Your server responds with the following custom header to the preflight request:

Access-Control-All-Headers: Origin, X-Requested-With, Content-Type, Accept, Key

whereas if you (or the person who wrote this server) read carefully about CORS he should have responded with:

Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Key

Now the client client could go ahead and use the Key custom header.

This being said, Bearer is quite specific to OAuth 2 which is sent throughout the Authorization header. Using Key seems like a terrible violation of RFCs and stuff and a wheel reinvention kinda.

Please note the typo in Nyx's question and Darin's answer ('ow' missing). So it's

Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Key

and it resolves the error message 'Request header field some-header-field is not allowed by Access-Control-Allow-Headers in preflight mode', if sent as an answer to the browser's OPTION request.

Add this to your server response headers :

header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token , Authorization');

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!