【发布时间】:2013-05-31 05:37:24
【问题描述】:
我编写了以下控制器,用于使用 Angular JS 测试 HTTP Basic Auth。
function TestCtrl($scope, $http, Base64){
$http.defaults.headers.common.Authorization = 'Basic ' + Base64.encode('admin:secret');
$http.jsonp( 'http://localhost:5000/test'+'/?callback=JSON_CALLBACK', {query:{isArray:true }}).
then(function (response) {
$scope.test = response.data;
});
}
当我 console.log($http.defaults.headers) 时,我可以看到标题正在设置。但是,当我在 Firefox 中使用 Chrome 开发人员工具栏或 Firebug 检查请求标头时,我看不到授权标头。
接收请求的服务器没有获得授权标头。
我在这里做错了什么?
【问题讨论】:
-
您不能使用 JSONP 自定义标头。见stackoverflow.com/questions/3073287/…
-
谢谢.. 猜猜我应该使用 get 或 post。
标签: javascript angularjs basic-authentication