Ho problemi a trovare CORS abilitato sul mio server in combinazione con AngularJS. Sto usando angolare 1.2.16 e questa è la mia configurazione del server:AngularJS richiesta CORS intestazione personalizzata
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "Content-Type, X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Date, X-Api-Version, X-File-Name, Authorization"
Header set Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"
Header set Access-Control-Allow-Credentials "true"
posso utilizzare la seguente richiesta:
$http.post(configuration.authUrl, {username: 'username', password: 'password'})
.success(function (data) {
$cookieStore.put(configuration.sessionName, {
token: data.authenticationToken,
user: data.user
});
})
.error(function() {}));
poiché la richiesta non utilizza un header personalizzato.
Quando poi provo a richiedere: Balance.get()
con saldo è:
angular.module('portalApp')
.factory('Balance', ['$resource', 'Auth', 'configuration', function ($resource, Auth, configuration) {
return $resource(configuration.balanceUrl, {}, {
get: {
method: 'GET',
isArray: false,
headers: {
Authorization: Auth.getAuthToken()
}
}
});
}]);
ottengo un 401 Unauthorized
sul balanceUrl.
Nel config ho messo:
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
Ho anche provato a mettere $http.defaults.headers.common.Authorization = Auth.getAuthToken();
prima della $resource
in fabbrica risorsa Balance
ma che non ha aiutato.
Le intestazioni inviate alla richiesta preflight OPTIONS
non hanno l'intestazione Authorization
, indipendentemente dal metodo che utilizzo. Queste sono le intestazioni di richiesta della richiesta preflight OPTIONS
.
OPTIONS /api/v1.0/user/orders HTTP/1.1
Host: host
Connection: keep-alive
Cache-Control: no-cache
Access-Control-Request-Method: GET
Pragma: no-cache
Origin: origin
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
Access-Control-Request-Headers: accept, authorization
Accept: */*
Referer: referer
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Qualche suggerimento?
sì, non è possibile, http: // StackOverflow.com/a/19744754/101662 – Oliver