0
我試圖用Restangular對JAX-RS REST服務(即啓用COR)執行以下調用。Restangular No'Access-Control-Allow-Origin'標題出現在請求的資源上
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 OPTIONS調用是問題,但也是返回相同的CORs標題。
好吧我實際上決定添加Access-Control-Allow-Credentials,因爲我認爲這樣可以解決問題。我沒有Cookie或憑證,所以我實際上不需要這些。所以我遇到了同樣的問題,使用Access-Control-Allow-Credentials而不是返回的頭文件 – DarVar