Request header field x-access-token is not allowed by Access-Control-Allow-Headers

為{幸葍}努か 提交于 2021-02-20 03:49:43

问题


I am stuck with this error. please help..

XMLHttpRequest cannot load. Request header field x-access-token is not allowed by Access-Control-Allow-Headers.


回答1:


Your server should return that it accepts custom headers (like x-access-token). For example, if you are using nodejs with expressjs, try this:

app.use(function(req, res, next) {
   res.header("Access-Control-Allow-Origin", "*"); // keep this if your api accepts cross-origin requests
   res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, X-Access-Token");
   next();
});

If your server is in PHP, you need to do the same:

header("Access-Control-Allow-Origin: *"); // keep this if your api accepts cross-origin requests
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, X-Access-Token");

Ps: Access-Control-Allow-Headers doesn´t accept wildcards '*' as value.



来源:https://stackoverflow.com/questions/39345378/request-header-field-x-access-token-is-not-allowed-by-access-control-allow-heade

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