AngularJS:从HttpResponse中读取数据和标头

AngularJS: reading both data and headers from a HttpResponse

本文关键字:数据 读取 HttpResponse AngularJS      更新时间:2024-04-17

我有一个REST API(使用Spring Boot开发),我在前端使用AngularJS 1.5,登录服务除了发送数据外还发送一个头,我如何在AngularJS侧中读取数据和头

var LocalBusinessUserResource = $resource(apiService + '/localbusinessusers/login');
var deferred = $q.defer();
            LocalBusinessUserResource.get(credantials, function (result) {
                console.log('result: ' + JSON.stringify(result));
                deferred.resolve(result);
            }, function () {
                console.error('check your server connection');
            });
            return deferred.promise;

来自$http文档:

响应对象具有以下属性:

data – {string|Object} – The response body transformed with the transform functions.
status – {number} – HTTP status code of the response.
headers – {function([headerName])} – Header getter function.
config – {Object} – The configuration object that was used to generate the request.
statusText – {string} – HTTP status text of the response.

您可以访问从中获取响应数据的同一对象上的响应标头。