自定义标头无法使用$ resource工作

时间:2014-02-21 17:49:35

标签: angularjs

我已经创建了自定义标题但是当我调用该服务时,我得到了响应401 Unauthorized.Can有些人指出了标题中的问题?

 function getInsuredWebAccount(insuredId) {

        var deferred = $q.defer();
        var web = $resource(webAccountServiceHostName, {}, {
            query: {
                method: 'Get',
                headers: {
                    Authorization:'Bearer c3J1bml0ZTo1OUJFODUwNUIyRjM0OEVGQTI1RTU1RjU4NEVGNUE0'
                }
            }                    
        });
        web.get({ insuredId: insuredId }, function onSuccess(response) {

            var webInfo = response;
            deferred.resolve(response);

        }, function onFailure(response) {
            deferred.reject(response);
        });

        return deferred.promise;
    }

1 个答案:

答案 0 :(得分:0)

看起来您已将标题添加到您创建的查询操作/方法中,但之后您将调用标准的$ resource“get”方法。试试吧:

 web.query({ insuredId: insuredId }, function onSuccess(response) { ...