0
编辑: 原来这是在Apache配置服务器端解决的。但值得注意的是,授权头实际上包含在预检请求标头中,而不是主要请求中,这就是为什么它看起来不在标头中。
我有这个问题,这仍然是悬而未决描述了同样的问题:Angularjs set a authorization header
我需要在我的请求头授权令牌。
app.config(function($httpProvider) {
$httpProvider.defaults.headers.common['Authorization'] = '1234567';
});
而且这样的:我有这样的使用方法 - 一些我试着设置$ HTTP默认值如下试图
app.run(function($http) {
$http.defaults.headers.common['Authorization'] = '1234567';
});
此外,我试图构建我的请求,这样在一个方法我服务:
var request = {
method: 'GET',
url: 'my/api/endpoint',
headers: {
'Authorization': '1234567'
}
};
$http(request).then(function(response) {
console.log(response);
});
在所有这些情况下,我最终在我的请求头看到的是这样的:
Access-Control-Request-Method: GET
Origin: http://localhost:8000
Access-Control-Request-Headers: accept, authorization
Accept: */*
Referer: http://localhost:8000/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
我希望看到有另一种键值对,如:
Authorization: '1234567'
但是,我不知道。
我正在使用Angular版本1.4.9,不知这个问题是否特定于此版本?
它最终成为服务器端的问题,但仍然是upvoting,因为这是一个很好的建议。 :) – kfhohn