我想在标头中发送数据,因此我将数据转换为base64,然后我在$http.defaults.headers.common['Authorization']
中获取输出。但是如何在帖子请求中的标题中发布基本身份验证数据
.factory('Auth', function (Base64,$http, AuthToken) { //for login/logout
var authFactory = {};
authFactory.login = function (loginData) {
var authdata = Base64.encode(loginData.username + ':' + loginData.password);
var userData = {
username: loginData.username ,
authdata: authdata
}
$http.defaults.headers.common['Authorization'] = 'Basic ' + authdata;
return $http.post('http://cc92e1dd.ngrok.io/api/authenticate',{'Authorization':'Basic ' + authdata})//is this correct format to send?
.then(function (data) {
AuthToken.setToken(data.data.token);
return data;
});
};
答案 0 :(得分:0)
如下所示,只需将params放入标题:
$http.get(url,
{ headers: {
'Cache-Control' : 'public',
'Pragma': '',
'Accept-Encoding':
'gzip, deflate, br',
'Authorization': 'Basic ' + authdata
}
});