离子应用程序不发送授权标头.尽管授权标头列在允许的标头中,但标头值根本不存在.
我使用NodeJS Express和MongoDB作为后端这里是我的CORS标题
<code>
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods',
'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Expose-Headers',
'X-Authorization-Token, Authorization');
res.header('Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept, Authorization'
);
And Here Is My AuthInterceptor
return {
request: function(config) {
var token = authToken.getToken();
if (token) {
config.headers.Authorization = 'Bearer ' + token;
}
return config;
},
response: function(response) {
return response;
}
};
My $http
return $http(options).success(function(response) {
self.currUser = response.profile;
if (_.contains(response.profile.roles, 'admin') ||
!((_.contains(response.profile.roles, 'lecturer')) || (_.contains(
response.profile.roles, 'evaluator')))) {
$state.go('admin');
}
})
</code>
最佳答案 我遇到过同样的问题.我想出解决问题的唯一方法是添加:
"proxies": [
{
"path": "/<your local url>",
"proxyUrl": "http://<remote_url>"
}
],
到我的ionic.project文件.