我想从api获取数据(具有基本身份验证)。我通过了用户名和密码,但我仍然遇到未经授权的错误。如何解决未经授权的error.api发送json数据但我无法访问它。
代码:
<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>