在开发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

 

相关文章:

  • 2021-07-06
  • 2018-08-29
  • 2021-09-23
  • 2022-12-23
  • 2021-07-01
  • 2022-12-23
  • 2021-04-17
  • 2021-12-24
猜你喜欢
  • 2021-10-11
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案