Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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
AngularJS:使用auth头获取受保护的JSON_Angularjs_Xmlhttprequest_Angular Http Auth - Fatal编程技术网

AngularJS:使用auth头获取受保护的JSON

AngularJS:使用auth头获取受保护的JSON,angularjs,xmlhttprequest,angular-http-auth,Angularjs,Xmlhttprequest,Angular Http Auth,我有一个由服务器生成的JSON文件,要通过浏览器中的URL访问该JSON,我需要登录并提供用户名和密码 现在我正在尝试使用Angular获取JSON,尽管找不到有效的解决方案。 我已经拥有的: $scope.dane = []; $http.jsonp('myURLwithUserAndPass?callback=JSON_CALLBACK') .success(function(data) { console.log('DATA pass'); $scope.dane =

我有一个由服务器生成的JSON文件,要通过浏览器中的URL访问该JSON,我需要登录并提供用户名和密码

现在我正在尝试使用Angular获取JSON,尽管找不到有效的解决方案。 我已经拥有的:

$scope.dane = [];

$http.jsonp('myURLwithUserAndPass?callback=JSON_CALLBACK')
  .success(function(data) {
    console.log('DATA pass');
    $scope.dane = data.products; // response data
  }).error(function() {
    console.log('DATA failed');
  });
这会在控制台中产生错误:

未捕获的语法错误:意外标记

资源被解释为脚本,但使用MIME类型text/json:myURLwithUserAndPass?callback=angular.callbacks传输。\u 0

我尝试在配置中添加auth头,如下所示:

$httpProvider.defaults.headers.common['Authorization'] = 'Basic ' + myusername + ':' + mypassword;
…但这没用。 我还尝试在URL中传递用户名和密码,如下所示:

$http.jsonp('myURLwithUserAndPass?callback=JSON_CALLBACK&userID=SomeUSER&password=SomePSWD ').

关于如何访问JSON有什么帮助吗?

什么样的身份验证?基本,OAuth…?用户名:密码必须是base64 encodedtry才能这样做,并告诉您在浏览器中看到的内容:注意:在console.log'DATA pass'之后添加这一行;控制台日志数据;