前端項目跨域請求報錯


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM