我在尝试访问浏览器网络检查器中(上面的链接)可以看到 'error-detail' 首部已返回。在服务器端,我还将自定义首部添加到 'Access-Control-Expose-Headers' 中,以允许跨域请求,因为其他问题建议采用此方法进行修复。
下面是向服务器发送请求以及成功/错误回调的代码:
this.signon = function (request, onComplete, onError) {
console.log("Calling server with 'login' request...");
return $http.post("http://localhost:8080/markit-war/services/rest/UserService/login/", request)
.then(onComplete, onError);
};
var onLookupComplete = function(response) {
if (response.data.username)
{
//If user is returned, redirect to the dashboard.
$location.path('/dashboard');
}
$scope.username = response.data.username;
};
var onError = function(response) {
$scope.error = "Ooops, something went wrong..";
console.log('error-detail: ' + response.headers('error-detail'));
};
当我尝试访问如下所示的响应头时:
console.log(response.headers());
console.log('error-detail: ' + response.headers('error-detail'));
这只输出:
content-type:"application/json"
error-detail:null
为什么error-detail头部没有被映射到响应对象中呢?