我在本地虚拟主机 ( http://foo.app:8000 ) 上运行一个 angular 应用程序。它正在使用 $http.post
向另一个本地 VirtualHost ( http://bar.app:8000 ) 发出请求.
$http.post('http://bar.app:8000/mobile/reply', reply, {withCredentials: true});
在 Chrome 开发者工具的 Network 选项卡中,我当然会看到 OPTIONS 请求,响应包括标题:
Access-Control-Allow-Origin: http://foo.app:8000
但是,POST 请求被取消并出现以下错误:
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
header 非常清楚地包含在 OPTIONS 请求的响应中,所以我一生都无法弄清楚为什么 POST 会导致 header 丢失。Access-Control-Allow-Credentials
也设置为 true
.
最佳答案
这是本地开发人员在 chrome 中的一个错误。尝试其他浏览器。然后它会起作用。
关于AngularJS 没有检测到 Access-Control-Allow-Origin header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21102690/