Set your default headers ONCE
In AngularJs 1.1.4 (the only version I tested this in), if you set $http.defaults.headers.post
twice, the second configuration will overwrite the first, so set an object of key:value
pairs once instead of doing them one at a time.
Do this.
$http.defaults.headers.post = {
'My-Custom-Header': obj.val,
'X-Forwarded-User': obj.userid
};
Not this.
$http.defaults.headers.post = {
'My-Custom-Header': obj.val
};
$http.defaults.headers.post = {
'X-Forwarded-User': obj.userid
};
In this second example, your POSTs will only have the X-Forwarded-User
header set, My-Custom-Header
will NOT be there.
Written by Dan Kapusta
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Angularjs
Authors
Related Tags
#angularjs
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#