Cors Restangular请求的资源上不存在“Access Control Allow Origin”标头

Cors Restangular请求的资源上不存在“Access Control Allow Origin”标头,cors,restangular,Cors,Restangular,我尝试使用restanglar对启用CORs的JAX-RSREST服务执行以下调用 var baseUsers = Restangular.all("users"); $scope.users = '{[]}'; $scope.users = baseUsers.getList().then(function(result) { console.log("Got users", response.status); }, function(res

我尝试使用restanglar对启用CORs的JAX-RSREST服务执行以下调用

    var baseUsers = Restangular.all("users");

    $scope.users = '{[]}';

    $scope.users = baseUsers.getList().then(function(result) {
        console.log("Got users", response.status);
    }, function(response) {
        console.log("Failed to find users with status code", response.status);
    });
但我一直在控制台中看到这个错误:

XMLHttpRequest cannot load http://135.60.151.27:9080/app/users. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8383' is therefore not allowed access.
从邮递员处,我可以在回复中看到CORs标题:

Access-Control-Allow-Credentials →true
Access-Control-Allow-Headers →Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since
Access-Control-Allow-Methods →GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin →*
Content-Length →2
Content-Type →application/json
Date →Thu, 03 Jul 2014 14:34:25 GMT
X-Powered-By →Servlet/3.0
我认为可能是REST选项调用出现了问题,但这也返回了相同的CORs头。

访问控制允许凭据:true与访问控制允许源代码不混合:*

在:

字符串*不能用于支持凭据的资源

当您允许凭据时,允许任何来源都是非常不安全的。这样,您在互联网上访问的任何网站理论上都可以在未经您同意甚至未经您通知的情况下代表您在配置错误的网站上进行操作


因此,您应该在Access Control Allow Origin中只包含一台主机,或者实现一个系统,如果主机请求头与预定义的白名单/regexp匹配,则从主机请求头添加主机名。

Ok我实际上决定添加Access Control Allow凭据,因为我认为这样可以解决问题。我没有饼干或证书,所以我实际上不需要这个。因此,我遇到了相同的问题,访问控制允许凭据未包含在返回的头中