ngResource和Access-Control-Allow-Origin

时间:2014-08-03 21:25:25

标签: angularjs rest cors

我已经使用带有CORS过滤器的java和jetty设置了一个REST服务:

    response
        .header("Access-Control-Allow-Origin", "*")
        .header("Access-Control-Allow-Methods", "GET, POST, OPTIONS, DELETE, PUT");

然后我尝试使用AngularJS和ngResource从其余服务获取数据:

$scope.nodes = $resource("http://localhost:8080/rest/forum/categories").query();

当我运行代码时,我在控制台日志中收到以下消息:

XMLHttpRequest cannot load http://localhost/rest/forum/categories. 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://localhost:7000' is therefore not allowed access.

它似乎已经以某种方式从URL中删除了:8080。

当我尝试仅使用浏览器获取REST URL时,一切都很好。我甚至检查了返回的HTTP头:

Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE, PUT 
Access-Control-Allow-Origin:* 
Content-Type:application/json

有人能说出我在哪里出错吗?

0 个答案:

没有答案