angularjs基本认证头基本、angularjs

由网友(你是触不到的星辰)分享简介:我试图连接到API和发送认证头。我使用的Base64这里描述我如何获得基本身份验证在angularjs工作? I'm trying to connect to API and send authentication headers. I'm using Base64 as described here How do...

我试图连接到API和发送认证头。我使用的Base64这里描述我如何获得基本身份验证在angularjs工作?

I'm trying to connect to API and send authentication headers. I'm using Base64 as described here 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);
        });
}

但我得到这个错误

but i'm getting this error

XMLHtt prequest无法加载的https://.../Category.json回调= ?无访问控制允许来源标头的请求的资源present。产地:因此 HTTP //....com '是不允许访问。响应有HTTP状态code 400。

XMLHttpRequest cannot load https://.../Category.json?callback=?. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://....com' is therefore not allowed access. The response had HTTP status code 400.

推荐答案

看起来你正在运行与跨域资源共享(CORS)的问题。有一个读:How不访问控制允许来源头工作?

Looks like you are running into issues with Cross-Origin Resource Sharing (CORS). Have a read of: How does Access-Control-Allow-Origin header work?

如果你控制了服务器,那么你可以把它发回一个适当的访问控制允许来源头按什么服务器code中的问题你引用(我得到基本身份验证在angularjs工作怎么办?)

If you control the server then you can have it send back an appropriate Access-Control-Allow-Origin header as per what the server code in the question you referenced (How do I get basic auth working in angularjs?)

阅读全文

相关推荐

最新文章