AngularJS $资源不发送自定义页眉 [英] AngularJS $resource not sending custom headers

查看:102
本文介绍了AngularJS $资源不发送自定义页眉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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


解决方案

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

编辑:

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

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.

这篇关于AngularJS $资源不发送自定义页眉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆