简体   繁体   English

如何让我的ngResource接受自定义标头?

[英]How can I get my ngResource to accept custom headers?

My code in coffeescript : 我在coffeescript中的代码:

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

My code in javascript : 我在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. 它不发送那些指定的头,并且有效地失败了CORS授权。

Any recommendations? 有什么建议?

Looks like that headers setting is only available in the latest "unstable" release of Angular. 看起来标题设置仅在Angular的最新“不稳定”版本中可用。 If you use this, be sure to upgrade both angular.js and angular.resource.js to 1.1.2 (current unstable release). 如果使用它,请确保将angular.js和angular.resource.js升级到1.1.2(当前不稳定版本)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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