AngularJS-无法从$http读取响应头
当我使用检查器检查请求时,我的http响应包含头身份验证(如此处所述:AngularJS-无法从$http读取响应头,angularjs,http-headers,angular-http,Angularjs,Http Headers,Angular Http,当我使用检查器检查请求时,我的http响应包含头身份验证(如此处所述:Authentication:76efbc0946773b62c93e952b502a47acd898200f6f80dc46ac87ffc501c00780),但调用头(“身份验证”)返回null return $http({ method: "GET", url: url, headers: { 'Content-Type': "application/json" } }).su
Authentication:76efbc0946773b62c93e952b502a47acd898200f6f80dc46ac87ffc501c00780
),但调用头(“身份验证”)
返回null
return $http({
method: "GET",
url: url,
headers: {
'Content-Type': "application/json"
}
}).success(function (data, status, headers, config) {
console.log(headers("Authentication"));
})
你知道我怎么会做得不对吗
仅供参考,我已尝试使用
将其切换回“承诺”方式。然后
,问题仍然是一样的。在成功回调中:
console.log(headers('content-type'));
console.log(headers()); // All headers
我认为第一行会在您的cas中返回一个结果。第二,你有“认证”吗
自定义标题将在同一域中可见。在跨域情况下,您需要从服务器发送
访问控制公开头:身份验证,
头 您的代码看起来不错,但如果是CORS请求,服务器需要在响应中包含访问控制公开头:{any custom Headers}
前面有一个问题/答案,提供了更多详细信息:您可能需要在服务器的响应中添加访问控制公开标题,以使其可访问-请参阅@BradBarber,仅此而已。如果你想获得赏金,请回复。启用CORS不会影响安全。我们不应该在响应体中发送所需的数据吗。