0

I was wondering if there is any way to send the same header to different requests.

I saw this AngularJS $http custom header for all requests but http interceptor is for all http requests and I don't want that each http request get this header.

There is other way to do this for different request without sending it manually for each request?

Sorry for my english and thanks in advance!

Sagie
  • 996
  • 3
  • 12
  • 25

2 Answers2

0

Yes you can ! below is an example straight from the Docs:

var req = {
 method: 'POST',
 url: 'http://example.com',
 headers: {
   'Content-Type': undefined
 },
 data: { test: 'test' }
}

$http(req).then(function(){...}, function(){...});

You can set different headers for each of your $http calls !

Rathma
  • 1,196
  • 2
  • 33
  • 65
0

you can still use http interceptor with check on request url

function HttpInterceptor() {
    var interceptor = {
        request: function (request) {
            if (request.url === 'request_url1' || request.url === 'request_url2'){
                request.headers['custom_header'] = 'this is conditional header';
            }
            return request;
        },
        response: function (response) {
            console.log(response);
            return response;
        }
    };
    return interceptor;
}
Mohit Patil
  • 436
  • 1
  • 5
  • 15