温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ant design pro开发碰到的跨域问题

发布时间:2020-04-27 22:43:38 来源:网络 阅读:6947 作者:netbird_fly 栏目:web开发

跨域问题

为了让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');

问题得到解决。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI