前端项目跨域请求报错

在开发VUE前端项目访问服务端的接口的时候报错:

Access to fetch at

'https://xxx.xxx.com/xxx/xxx/xxx?param=xxx' from origin 'http://xxx.xxx.com:xxx'

has been blocked by CORS policy:

Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

大致意思是:是一个跨域请求我的没有访问该地址的权限(接口服务器采用的是PHP编写)

解决方案:

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

具体请参考以下网址:

https://www.cnblogs.com/jasonLiu2018/p/10939304.html

https://blog.csdn.net/abs1004/article/details/76895652

原文地址:https://www.cnblogs.com/gougou1981/p/14309216.html