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

angular – CLI CORS代理不改变原点,仍然获得403 reqs?

发布时间:2020-12-17 17:43:42 所属栏目:安全 来源:网络整理
导读:是的,我发现了很多相似的东西,但仍未解决我的实例.我想避免杀死浏览器端的安全性,而是让代理完成它的工作,但我担心我在设置中遗漏了一些无聊的细节,我无论如何都不是CORS专家. 所以,我得到的…… 403; Failed to load http://localhost:10000/some/rest/endp
是的,我发现了很多相似的东西,但仍未解决我的实例.我想避免杀死浏览器端的安全性,而是让代理完成它的工作,但我担心我在设置中遗漏了一些无聊的细节,我无论如何都不是CORS专家.

所以,我得到的…… 403;

Failed to load http://localhost:10000/some/rest/endpoint: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.

其中localhost:10000是我的api url,并且:4200是默认的Angular CLI实例.

所以我配置了一个代理,因为我希望在angular.json中这样做;

"serve": {
          "builder": "@angular-devkit/build-angular:dev-server","options": {
            "browserTarget": "angular-proj:build","proxyConfig": "./proxy.conf.json"
          },

并添加proxy.conf.json;

{
    "/some/rest/*": {
      "target": "http://localhost:10000","secure": false,"changeOrigin": true,"logLevel": "debug"
    }
  }

我提供它甚至标记CLI服务确认的proxy.conf;

创建了[HPM]代理:/ some / rest – > http:// localhost:10000等…

….除了我仍然得到403,仍然在Request *标题中看到;

Host: localhost:10000
Origin: http://localhost:4200

所以我的问题是,我在这里错过了什么内容?我不想把所有来源的请求写成星号,而且我不想关闭浏览器检查,我更愿意将这个很好地捆绑在服务配置中,就像我这样做另外一对眼睛非常受欢迎.干杯

ADDENDUM:我的GET看起来很好但是像Access-Control-Request-Method这样的东西:POSTshows作为请求方法:OPTIONS,那就是我得到我的403 …为什么POST会变成OPTIONS?

ADDENDUM#2:值得一提的是,我在Chrome / Firefox中遇到了这个问题,但Edge中的一切都是犹太人的???

ADDENDUM#3:运行时使用代理作为–aot = true.

解决方法

以下标头是错误的,这就是为什么您的浏览器仍然触发“相同的Origin策略”握手:

Host: localhost:10000
Origin: http://localhost:4200

他们应该是:

Host: localhost:4200
Origin: http://localhost:4200

我坚信你没有将你的请求从http:// localhost:10000 / *更改为http:// localhost:4200 / some / rest / *并且“类似的东西”没有包含这个:Angular2 CORS issue on localhost

(编辑:李大同)

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

    推荐文章
      热点阅读