Request header field Content-Type is not allowed by Access-Control-Allow-Headers跨域

悬崖之上 后端 前端 2019-05-28

跨域错误提示:

XMLHttpRequest cannot load http://xxx.com. Request header field Content-Type is not allowed by Access-Control-Allow-Headers.

解决方案:

php服务端程序设置头:

header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, x-file-name");
header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE');

其实主要是看console返回的错误信息,适当修改以上代码的参数。哪个被拒绝了,就添加哪一个。

Apipost 私有化火热进行中

评论