加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

laravel – Angular 2 – 请求的资源上没有“Access-Control-All

发布时间:2020-12-17 07:56:45 所属栏目:安全 来源:网络整理
导读:当我尝试从我的Angular 2 App到我的API进行API调用时,出现以下错误: XMLHttpRequest cannot load http://localhost/myAPI/public/api/v1/auth/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://local
当我尝试从我的Angular 2 App到我的API进行API调用时,出现以下错误:
XMLHttpRequest cannot load http://localhost/myAPI/public/api/v1/auth/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 422.

我一直在检查网上的每一个问题以及任何与CORS相关的问题,没有解决我的问题!

我的Laravel API在端口80上运行.(localhost)

我的角度2应用程序在端口3000上运行.(localhost:3000)

>我一直在尝试用Cors中间件启用Laravel方面的cors
> API调用正在使用chrome web security off.第一个答案here解决了问题,但我真的想在每次测试我的应用时停止使用CMD和不安全的chrome版本.
>使用chrome扩展POSTMAN API调用我的API正在运行.

那么……怎么了?为什么我的Angular 2应用程序无法从我的API获取记录?

好.似乎需要为它配置apache.

我正在使用xampp webserver,我必须按照here的解释编辑我的httpd.conf来解决这个问题.

添加此行:

Header set Access-Control-Allow-Origin "http://localhost:3000"

解决了我的问题.

必须重新启动apache.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读