Click here to Skip to main content
15,888,273 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a REST service running on server.

I have Chrome Postman to access that service with Basic Authentication, and I can access that service with this Post man.

But, now I want to create a UI to show received data from REST in AngularJS.

How I can call this REST service by using AngularJS with Basic Authentication?
I have username and password.

Thanks,
Ashok

What I have tried:

This is what I tried, but dont know how to pass Basic Authentication credentials

function getDataByAjax($scope, $http, url) {
$http.get(url).
success(function (data) {
$scope.greeting = data;
}).
error(function (data, status, headers, config) {
debugger;
alert("erro");
});
}
Posted
Updated 17-Feb-16 20:14pm
Comments
Kornfeld Eliyahu Peter 16-Feb-16 5:07am    
RTFM...
https://docs.angularjs.org/api/ng/service/$http
Ashokyede 16-Feb-16 5:23am    
Thanks for your reply. I didn't found Basic Authentication explanation there. Can you please provide me the example with Basic Authentication? I searched on Google, but didn't get the useful solution.
Kornfeld Eliyahu Peter 16-Feb-16 5:25am    
If you didn't found - you din't read it!
Ashokyede 16-Feb-16 6:17am    
http.defaults.headers.common.Authorization = 'Basic cm9fdgC11c2VyOk1pas4xMi5jaGFycw==';, is this is what you are talking about? is it okay to assign this credentials for every request?

1 solution

Thanks Peter for your help.

JavaScript
$http.defaults.headers.common.Authorization = 'Basic  dfdstdfvsae3fewrew54ser4w;;



This worked for me..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900