Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在angular js中访问基本身份验证api时发生未经筛选的错误_Javascript_Angularjs - Fatal编程技术网

Javascript 在angular js中访问基本身份验证api时发生未经筛选的错误

Javascript 在angular js中访问基本身份验证api时发生未经筛选的错误,javascript,angularjs,Javascript,Angularjs,我想从api(具有基本身份验证)获取数据。我正在传递用户名和密码,但仍然收到未经授权的错误。如何解决未经授权的错误。api发送json数据,但我无法访问它 代码: <body> <div ng-app="myApp" ng-controller="customersCtrl"> <table> <tr ng-repeat="x in names"> <td>

我想从api(具有基本身份验证)获取数据。我正在传递用户名和密码,但仍然收到未经授权的错误。如何解决未经授权的错误。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>

{{x.name}
{{x.city}
var-app=angular.module('myApp',[]);
app.controller('customersCtrl',函数($scope,$http){
$http.get('https://example.com/node1', {
标题:{'Authorization':'user1:user1@123' }
}).then(函数(响应){$scope.names=response.data.records;});
});

您是否检查了cors问题?-你得到了什么样的回应?你能在响应函数中添加一个
console.log
并共享它吗?我为chrome安装了cors插件。因此,它暂时解决了您可能希望在发送密码之前尝试对密码进行哈希处理。从技术上讲,没有人能回答这个问题,这只能是猜测。API文档将告诉您需要做什么。如果你能提供一个到API文档的链接,我们也许能解决这个问题。根据你的评论,你没有遵循API文档。它表示您需要传递
[username:password]
base64编码。您现在的问题是否已改为如何对密码进行编码?