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

跨域問題

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

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

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設置是這樣

    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端又增加了:

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

問題得到解決。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章