标签: angular-http-auth

angularjs基本身份验证标头

我正在尝试连接到API并发送身份验证标头.我正在使用这里描述的Base64 如何在angularjs中获得基本的auth工作?

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);
        });
}
Run Code Online (Sandbox Code Playgroud)

但是我收到了这个错误

XMLHttpRequest无法加载https://.../Category.json?callback = ?. 请求的资源上不存在"Access-Control-Allow-Origin"标头.因此不允许来源' http://....com '访问.响应具有HTTP状态代码400.

http-authentication angularjs angular-http-auth

5
推荐指数
1
解决办法
2万
查看次数