在開發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