0

I have a JSON file generated by the server and to access that JSON via URL within the browser I need to log in providing username and password.

Now I am trying to get that JSON with Angular, although can't find working solution. What I already have:

$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');
  });

This produces errors in the console:

"Uncaught SyntaxError: Unexpected token"

and "Resource interpreted as Script but transferred with MIME type text/json: "myURLwithUserAndPass?callback=angular.callbacks._0"."

I have tried adding auth headers in the config like following:

$httpProvider.defaults.headers.common['Authorization'] = 'Basic ' + myusername + ':' + mypassword;

...but it doesn't help. I've also tried passing username and password in the URL like that:

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

Any help on how can I access that JSON?

3
  • What kind of authentication? Basic, OAuth ...? Commented Apr 16, 2015 at 12:01
  • 1
    username:password has to be base64 encoded Commented Apr 16, 2015 at 12:42
  • try to do that and tell what you see in your browser: notice: add this line after console.log('DATA pass'); console.log(data); Commented Apr 16, 2015 at 15:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.