Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t读取AngularJS拦截器中的响应数据和头_Angularjs_Angular Http Interceptors - Fatal编程技术网

Can';t读取AngularJS拦截器中的响应数据和头

Can';t读取AngularJS拦截器中的响应数据和头,angularjs,angular-http-interceptors,Angularjs,Angular Http Interceptors,我的服务器中有一个API,它发送一个响应http://localhost:8081/my/test/api 我正在尝试从angularJS中的拦截器读取自定义响应头: angular.module('oauth.interceptor', []).factory('readResponseHeader', ['$q', function ($q) { return { response': function(response

我的服务器中有一个API,它发送一个响应
http://localhost:8081/my/test/api

我正在尝试从angularJS中的拦截器读取自定义响应头:

angular.module('oauth.interceptor', []).factory('readResponseHeader', ['$q',
        function ($q) {
            return {
                response': function(response) {
                    console.log("response: %o", JSON.stringify(response));
                    console.log("headers: %o", response.headers());
                    return response;
                }
            }
        }
    ]);
但我得到的只是响应的空数据和标题。控制台日志显示以下json作为响应:

以及以下作为标题:

我希望我的
customHeader
会出现在那里,并且能够通过以下内容阅读:

response.headers().customHeader
但它显然不在那里(事实上,许多其他标题都丢失了!)。
我该怎么读呢?

我终于发现问题不在AngularJS部分,而是在服务器端部分

要点是,为了能够访问标头,服务器必须添加包含自定义标头名称的
访问控制公开标头
标头,类似如下:

Access-Control-Expose-Headers: customHeader
response.headers().customHeader
Access-Control-Expose-Headers: customHeader