AngularJS $http custom header for all requests -


i wondering if there way configure $http requests header adding custom info. config :

 var config = {headers: {             'authorization': 'basic d2vudhdvcnrobwfuoknoyw5nzv9tzq==',             'accept': 'application/json;odata=verbose'         }     }; 

but $http calls make in different services. i'm sure there solution :d.thanks

you can create $http interceptor extend header:

myapp.factory('httprequestinterceptor', function () {    return {      request: function (config) {          config.headers['authorization'] = 'basic d2vudhdvcnrobwfuoknoyw5nzv9tzq==';        config.headers['accept'] = 'application/json;odata=verbose';          return config;      }    };  });    myapp.config(function ($httpprovider) {    $httpprovider.interceptors.push('httprequestinterceptor');  });


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -