0
在第一步中,我讓誰returs與外地一個JSON一個$ HTTP POST請求「ACCESS_TOKEN」:在angularJS我想插入一個令牌,到http頭
angular
.module('obparticularesmx')
.controller('inicio2', inicio2);
function inicio2($scope, $rootScope, $state, $http){
$http({
method:'POST',
url:'https://example.token-services.com/token',
data : {
client_id: "1561a116-7bde-4967-8471-8d6fb62511fa"
},
headers: {
'Content-Type': 'application/xwwwurlencoded;'
}
}).success(function(data) {
$scope.token = data.access_token;
});
}
然後,我用的是工廠爲了把該令牌到頁眉:
.factory('httpRequestInterceptor', function ($rootScope) {
return {
request: function (config) {
config.headers = {'Authorization':'Bearer ' + $rootScope.token}
return config;
}
};
})
但是,當我發送的授權條目,我看到一個未定義的值:
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate, br
Accept-Language en-US,en;q=0.5
**Authorization** Bearer undefined
Host particulares-gw-obparticularesmx dev.appls.cto2.paas.gsnetcloud.com
Origin http://localhost:3000
Referer http://localhost:3000/
User-Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0
什麼是解決方案?
只要一提起來,一旦他們刷新應用程序,他們將不得不再次登錄,除非這不是問題。 – Rob