我编写了以下控制器,用于使用Angular JS测试HTTP基本身份验证。无法在AngularJS中设置HTTP基本身份验证标头
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)
。但是,当我使用Chrome Developer Toolbar或Firefox中的Firebug检查请求标题时,我看不到授权标头。
接收请求的服务器没有获得授权标头。
我在做什么错在这里?
您无法使用JSONP自定义标头。见http://stackoverflow.com/questions/3073287/set-headers-with-jquery-ajax-and-jsonp –
谢谢..猜猜我应该使用get或post然后。 – Manu