0

Using Ajax in Angular I want to get some data from a URL that needs authentication. The curl command for getting this data outside of ajax is:

curl -u some_username:password 'https://website.com'

enter image description here

This is my function:

function getCurlData() {

  window.btoa("some_username:password");
  return $http.get("https://website.com").success( function(data) {
   console.log(data); 
  }).catch(function() {
     console.log("failed");      
 });

However I get a 403 forbidden message upon using this function. How can I retrieve the data?

3
  • Construction of the Authorization header is described in Wikipedia Basic Access Authorization. Be aware that the server needs to set the CORS Access-Control-Allow-Credentials Header. Commented Feb 3, 2017 at 2:53
  • $http({ method: 'GET', url: url, headers: { 'Authorization': "Basic "+auth64EncodedUserColonPass }}). Be aware of CORS too. Commented Feb 3, 2017 at 6:09
  • @msnfreaky I have a CORS Chrome Plugin but it still gives me an issue of access control :/ Commented Feb 3, 2017 at 17:13

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.