È possibile utilizzare le intestazioni predefinite per angolare 1.0.x:
$http.defaults.headers.common['Authentication'] = 'authentication';
o richiesta di intercettazione per angolari 1.1.x +:
myapp.factory('httpRequestInterceptor', function() {
return {
request: function (config) {
// use this to destroying other existing headers
config.headers = {'Authentication':'authentication'}
// use this to prevent destroying other existing headers
// config.headers['Authorization'] = 'authentication';
return config;
}
};
});
myapp.config(function ($httpProvider) {
$httpProvider.interceptors.push('httpRequestInterceptor');
});
Dal fabbriche/servizi sono single, questo funziona finché non è necessario modificare dinamicamente il valore di 'autenticazione' dopo che il servizio è stato istanziato.
fonte
2013-11-29 23:08:42
Puoi approfondire cosa intendi normalizzando i nomi dei tasti? – Webnet
Quando si ottengono le intestazioni usando il metodo headers(), la chiave "Auth-Token" diventa minuscola e diventa "auth-token". Che è fonte di confusione – lucassp
@lucassp può essere questo - http://stackoverflow.com/questions/5258977/are-http-headers-case-sensitive – KrIsHnA