Adding a custom header to HTTP request using angular.js

前端 未结 8 1821
说谎
说谎 2020-11-27 13:01

I am a novice to angular.js, and I am trying to add some headers to a request:

   var config = {headers: {
            \'Authorization\': \'Basic d2VudHdvcnR         


        
8条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 13:42

    If you want to add your custom headers to ALL requests, you can change the defaults on $httpProvider to always add this header…

    app.config(['$httpProvider', function ($httpProvider) {
        $httpProvider.defaults.headers.common = { 
            'Authorization': 'Basic d2VudHdvcnRobWFuOkNoYW5nZV9tZQ==',
            'Accept': 'application/json;odata=verbose'
          };
    }]);
    

提交回复
热议问题