title: Angular Js - set token on header default
body: <p>Im trying to add a header with my access token to each API call. It works well for all the GET requests, but as soon as I try to make a POST the header isn't added. </p>
  
  <p>Here is how I add the token:</p>
  
  <pre><code>app.factory('api', function ($http, $cookies) {
  return {
      init: function (token) {
          $http.defaults.headers.common['Token'] = token || $cookies.loginTokenCookie;
      }
    };
  });
  </code></pre>
  
  <p>Which gets called from here:</p>
  
  <pre><code>app.run(function ($cookies, $http, $location, $rootScope,api) {
      $rootScope.location = $location;
      api.init();
  });
  </code></pre>
  
  <p>I have tried doing it like the following:</p>
  
  <pre><code>app.factory('api', function ($http, $cookies) {
  return {
      init: function (token) {
          $http.defaults.headers.common['Token'] = token || $cookies.loginTokenCookie;
          $http.defaults.headers.post['Token'] = token || $cookies.loginTokenCookie;
  
      }
  };
  });
  </code></pre>
  
  <p>But this also doesnt work. It only works when I change the header key name like the following:</p>
  
  <pre><code> $http.defaults.headers.post['Token-Post'] = token || $cookies.loginTokenCookie;
  </code></pre>
  
  <p>How do I assign a default header to posts and get requests in AngularJs?</p>