Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I want to get data from api (having basic authentication). I'm passing username and password but still I'm getting unauthorized error. How to resolve unauthorized error.api sending json data but I'm not able access it .

Code:

<body>
    <div ng-app="myApp" ng-controller="customersCtrl">
        <table>
            <tr ng-repeat="x in names">
                <td>{{ x.name}}</td>
                <td>{{ x.city }}</td>

            </tr>
        </table>
    </div>
    <script>
    var app = angular.module('myApp', []);


    app.controller('customersCtrl', function($scope, $http) {
      $http.get('https://example.com/node1', {
          headers: { 'Authorization': 'user1:user1@123' }
      }).then(function (response) {$scope.names = response.data.records;});
    });


    </script>
</body>
</html>
share|improve this question
    
Did you check the cors issue? - devblast.com/b/cors-with-angular-js-and-sinatra – Reaz Murshed 22 hours ago
1  
What's the response are you getting ? Can you put a console.log in the response function and share it. – suzo 22 hours ago
    
i installed cors plugin for chrome. so it resolved for temporarily – Swapna 22 hours ago
    
You may want to try hashing the password before you send it. Technically no one can answer this question it can only be guessed at. The API documentation will tell you what you need to do. If you can provide a link to the API documentation we maybe able to work out the issue. – Emett Speer 22 hours ago
1  
according to your comment, you aren't following the API documentation. It says you need to pass the [username:password] base64 encoded. Has your question now changed to how to encode the password? – Claies 21 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.