How do I send multiple headers with angularJS resource?

佐手、 提交于 2019-12-11 03:01:40

问题


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?


回答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'
}



回答2:


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'}]
      }
    });


来源:https://stackoverflow.com/questions/27000698/how-do-i-send-multiple-headers-with-angularjs-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!