Angular JS를 사용하여 HTTP Basic Auth를 테스트하기 위해 다음 컨트롤러를 작성했습니다.AngularJS에서 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를 사용하여 요청 헤더를 확인할 때 Authorization 헤더가 표시되지 않습니다.
요청을 수신하는 서버가 Authorization 헤더를받지 못합니다.
내가 뭘 잘못하고있어?
헤더를 JSONP로 사용자 정의 할 수 없습니다. http://stackoverflow.com/questions/3073287/set-headers-with-jquery-ajax-and-jsonp –
고마워. 나는 get 또는 post를 사용해야한다. – Manu