Basic angularjs authentication headers

I am trying to connect to the API and send authentication headers. I am using Base64 as described here How can I get basic auth working in angularjs?

function Cntrl($scope, $http, Base64) { $http.defaults.headers.common['Authorization'] = 'Basic ' + Base64.encode('----myusername----' + ':' + '----mypass---'); $http({method: 'GET', url: 'https://.../Category.json'}). success(function(data, status, headers, config) { console.log('success'); }). error(function(data, status, headers, config) { alert(data); }); } 

but i get this error

XMLHttpRequest cannot load https: //.../Category.json? Callback = ?. The requested resource does not have an Access-Control-Allow-Origin header. The origin of http: //....com 'is therefore not allowed. The response was an HTTP 400 status code.

+5
source share
1 answer

Looks like you're facing Cross-Origin Resource Sharing (CORS) issues. Read: How does the Access-Control-Allow-Origin header work?

If you are managing a server, you can send it the corresponding Access-Control-Allow-Origin header in accordance with the server code in the question you referred to ( How to get basic work in angularjs? )

+3
source share

All Articles