【发布时间】:2015-03-13 06:58:50
【问题描述】:
我正在尝试连接到 API 并发送身份验证标头。 我正在使用这里描述的 Base64 How do 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);
});
}
但是我收到了这个错误
XMLHttpRequest 无法加载https://.../Category.json?callback=?。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'http://....com' 不允许访问。响应的 HTTP 状态代码为 400。
【问题讨论】:
标签: angularjs http-authentication angular-http-auth