Można użyć domyślnych nagłówków kątowym 1.0.x:
$http.defaults.headers.common['Authentication'] = 'authentication';
przechwytujących lub prośba o kanciastych 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');
});
Od Fabryki/usługi są samotnymi, to działa tak długo, jak długo nie trzeba dynamicznie zmieniać wartości "uwierzytelnienia" po utworzeniu usługi.
Czy możesz wyjaśnić, co masz na myśli, normalizując kluczowe nazwy? – Webnet
Podczas pobierania nagłówków za pomocą metody nagłówków() klucz "Auth-Token" staje się pisany małymi literami i staje się "auth-token". Co jest mylące. – lucassp
@lucassp może to być - http://stackoverflow.com/questions/5258977/are-http-headers-case-sensitive – KrIsHnA