【发布时间】:2014-05-14 19:26:37
【问题描述】:
我正在尝试将 AngularJS 与外部 API 一起使用。 API 使用 HTTP Basic 进行身份验证。
我已经查看了如何执行此操作,但似乎没有任何效果。 OPTIONS 请求总是在没有 Authorization 标头的情况下发送。
下面是一些示例代码:
var app = angular.module("BE", []);
app.controller("NextCtrl", function ($scope, $http) {
$http.defaults.headers.common['Authorization'] = 'Basic encoded_credentials';
$http.get('http://api-url.com').
success(function(data, status, headers) {
$scope.event = data.Event;
$scope.race = data.Race;
$scope.entrants = data.Entrants
}).
error(function(data, status, headers, config) {
// log error
});
});
如何使用为每个请求设置的 Authorization 标头发出请求?
【问题讨论】:
标签: angularjs