AngularJS $资源不发送自定义页眉页眉、自定义、资源、AngularJS

2023-09-13 04:08:50 作者:冷艳

我使用的角度和角速度资源1.1.5版,我使用$资源做出一个REST服务的请求。但似乎像自定义页眉不附加要求。我的定义是如下。有什么我做错了?

  myApp.factory(用户,函数($资源){    VAR用户= $资源(的http:// \\\\本地主机:7017 / MYDOMAIN /用户/千斤顶',{},{        得到:{            方法:GET,            IsArray的:假的,            标题:{'X-请求,通过':'ABC'}        }    });    返回用户;}); 

解决方案

阅读以了解如何在一个地方配置默认标题:的 http://docs.angularjs.org/api/ng.$http

编辑:

您标题必须包含在接入控制允许标题响应OPTIONS请求,这被送到自动之前的GET请求头。

AngularJS 应用访问 Android 手机的照片库

I'm using angular and angular-resource version 1.1.5 and I'm using a $resource to make a request to a REST service. But it seems like the custom headers is not appended to the request. My definition is as below. Is there anything I did wrong?

myApp.factory('User', function($resource) {
    var User = $resource('http://localhost\\:7017/mydomain/users/jack', { }, {
        get: {
            method: 'GET',
            isArray: false,
            headers: {'X-Requested-By':'abc'}
        }
    });
    return User;
});

解决方案

Read this to see how to configure default headers in one place: http://docs.angularjs.org/api/ng.$http

EDIT:

Your header must be included in Access-Control-Allow-Headers header in response to the OPTIONS request, which is sent automatically prior to your GET request.

 
精彩推荐