AngularJS 没有检测到 Access-Control-Allow-Origin 标头? [英] AngularJS not detecting Access-Control-Allow-Origin header?

查看:47
本文介绍了AngularJS 没有检测到 Access-Control-Allow-Origin 标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在本地虚拟主机 (http://foo.app:8000) 上运行 Angular 应用.它正在使用 $ 向另一个本地 VirtualHost (http://bar.app:8000) 发出请求http.post.

I am running an angular app on a local virtualhost (http://foo.app:8000). It is making a request to another local VirtualHost (http://bar.app:8000) using $http.post.

$http.post('http://bar.app:8000/mobile/reply', reply, {withCredentials: true});

在 Chrome Developer Tools 的 Network 选项卡中,我当然会看到 OPTIONS 请求,并且响应包含标题:

In the Network tab of Chrome Developer Tools I of course see the OPTIONS request, and the response includes the header:

Access-Control-Allow-Origin: http://foo.app:8000

但是,POST 请求被取消并出现以下错误:

However, the POST request is cancelled with the following error:

请求的资源上不存在Access-Control-Allow-Origin"标头.Origin 'http://foo.app:8000' 因此不允许访问.

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://foo.app:8000' is therefore not allowed access.

有人遇到过这种情况吗?Access-Control-Allow-Origin 标头非常清楚地包含在 OPTIONS 请求的响应中,所以我一生都无法弄清楚为什么 POST 会导致标头丢失.

Has anyone experienced this? The Access-Control-Allow-Origin header is very plainly included in the response of the OPTIONS request, so I can't for the life of me figure out why the POST is acting the header was missing.

Access-Control-Allow-Credentials 也设置为 true.

推荐答案

这是本地开发者在 chrome 中的一个错误.尝试其他浏览器.然后它会起作用.

It's a bug in chrome for local dev. Try other browser. Then it'll work.

这篇关于AngularJS 没有检测到 Access-Control-Allow-Origin 标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆