Access to XMLHttpRequest at <url> from origin <url> has been blocked by CORS policy【php】

2020-11-13 15:59:05 浏览数 (1)

1.前端报错

Access to XMLHttpRequest at 'http://localhost:8080/api/user/login' from origin 'http://localhost:808

2.开始以为是跨域问题

已经在入口文件增加header('Access-Control-Allow-Origin: *');//支持全域名访问

但是仍然不行

3.原因是前端使用了框架-axios

完整的配置

header('Pragma: no-cache', false); header('Access-Control-Allow-Origin: *');//支持全域名访问 header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE');//支持的http动作 header('Access-Control-Allow-Headers:x-requested-with,content-type');//响应头

0 人点赞