Jeremy Miller Jeremy Miller -4 years ago 88
AngularJS Question

How to not always send header in angular to external server

in my app.config i am sending

in header$http) {
$http.defaults.headers.common['MyCode'] = 'buTTon5';

Above works great for all my internal web api calls, but I do have some external api calls in which I cannot send them the header , how can I not send it,


XMLHttpRequest cannot load Request header field MyCode is not allowed by Access-Control-Allow-Headers in preflight response.

Answer Source

To delete you need to use interceptors. you will receive config object of $http call. check this updated plunker


  function($httpProvider) {
    $httpProvider.interceptors.push( function() {
      return {
        'request': function(config) {
          if (config.url.indexOf('') != -1)
            delete config.headers.MyCode; //able to delete with interceptor request method
          return config;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download