ant design pro開發碰到的跨域問題

跨域問題

爲了讓admin管理系統適應手機版,決定對首頁及各個功能頁進行升級。之前用admin antd design做爲腳手架進行開發發現對手機版支持很差。此次用ant design的pro版進行開發,重新搭建前端開發框架。前端

以前框架用axios做爲請求網絡的基礎組件,碰到了一些跨域問題,在個人另外一篇裏面介紹瞭解決方案。此次用的是dva/fetch裏面的fetch請求網絡數據,碰到新的跨域問題以下:ios

The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:8000' is therefore not allowed access.

ant design pro開發碰到的跨域問題

此時server設置是這樣axios

header('Access-Control-Allow-Origin: *');

修改以後:跨域

header('Access-Control-Allow-Origin:' . $_SERVER['HTTP_ORIGIN']);

又出現了新的問題:網絡

ant design pro開發碰到的跨域問題

The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. Origin 'http://localhost:8000' is therefore not allowed access.

因而在server端又增長了:antd

header('Access-Control-Allow-Credentials: true');

問題獲得解決。框架

相關文章
相關標籤/搜索