Search code examples
angularjsangular-resource

How do I send multiple headers with angularJS resource?


Trying to send multiple headers in the same request with angularJS this is what I have...

var auth = $resource("",
        {},
        {
          GetUserDetails: {
            url: Config.api.user.details(),
            method: 'POST',
            isArray: false,
            cache: false,
            headers: ["xx:xx","ff:ff"]
          }
        });

But the request just shows...

0:xx:xx
1:ff:ff
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Cache-Control:no-cache

Anyone know the right data structure to send a collection of headers down in the headers property on the resource?


Solution

  • Straight from the documentation:

    headers – {Object} – Map of strings or functions which return strings representing HTTP headers to send to the server. If the return value of a function is null, the header will not be sent.

    So what you need is:

    headers: {
        headerName1: 'headerValue1',
        headerName2: 'headerValue2'
    }