简体   繁体   中英

How can I get my ngResource to accept custom headers?

My code in coffeescript :

  resource = $resource GlobalService.apiRoot + "stuffs", {},
    get:
      method: "GET"
      headers:
        "Accept": "application/stuffs;version=3"
        "Authorization": 'Token token="' + $.cookie('token') + '"'

My code in javascript :

var resource;

resource = $resource(GlobalService.apiRoot + "stuffs", {}, {
  get: {
    method: "GET",
    headers: {
      "Accept": "application/stuffs;version=3",
      "Authorization": 'Token token="' + $.cookie('token') + '"'
    }
  }
});

Then when I do..

resource.get ->

It doesn't send out those specified headers, and effectually fails the CORS authorization.

Any recommendations?

Looks like that headers setting is only available in the latest "unstable" release of Angular. If you use this, be sure to upgrade both angular.js and angular.resource.js to 1.1.2 (current unstable release).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM