2

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?

Exitos
  • 29,230
  • 38
  • 123
  • 178

2 Answers2

1

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'
}
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Documentation? what's one of them then? :-) Thanks dude, I did look but didn't see it. Although looking... "Map of strings or functions" - I will have to learn what a map is in this case! Thanks will mark as correct as soon as 8 mins is up! – Exitos Nov 18 '14 at 17:59
0

Have you tried setting it up as

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