我是angularjs的新手。我正在嘗試提出需要授權的API請求。我已將它包含在請求的標題中,但仍不起作用。我確定我的訪問令牌正在工作。有什麼建議?AngularJS如何在Http請求中包含頭文件
$scope.fetch = function() {
$scope.code = null;
$scope.response = null;
$http({
method: $scope.method,
url: $scope.url,
cache: $templateCache,
headers: {
Authorization: "access token"
}
}).
success(function(data, status) {
$scope.status = status;
$scope.data = data;
}).
error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
};
在訪問令牌之前添加「Basic」。這裏可能的重複這裏http://stackoverflow.com/questions/11876777/angularjs-set-http-header-for-one-request –