如何在AngularJS中通过rest服务的基本身份验证?

如何在AngularJS中通过rest服务的基本身份验证?,angularjs,rest,basic-authentication,Angularjs,Rest,Basic Authentication,我有一个RESTWeb服务,它需要一个基本的身份验证来使用它的数据。我正在用AngularJS消费它 我的做法如下: $http.get('http://localhost:9200/persons/_search?_source=Gender', { headers: { withCredentials: true, headers:{ 'Authorization': 'Basic ' + btoa("admin" + ":"

我有一个RESTWeb服务,它需要一个基本的身份验证来使用它的数据。我正在用AngularJS消费它

我的做法如下:

$http.get('http://localhost:9200/persons/_search?_source=Gender', {
       headers: {
           withCredentials: true, 
            headers:{ 'Authorization':  'Basic ' + btoa("admin" + ":" + "admin")}

       }
   }).
        then(function(response) {
            ctrl.json = response.data;

        });       
}]);
但我在控制台中遇到的错误是:

不允许使用请求标头字段标头 访问控制允许飞行前响应中的标头


有人能帮忙解决这个问题吗?请注意,我已经在postman上对其进行了测试,它运行良好,正确地返回了我所有的数据。

这是CORS问题,您必须允许来自服务器的跨源请求。

这是CORS问题,您必须允许来自服务器的跨源请求。

我已经允许。但问题依然存在。有其他选择吗?您是如何允许的?http.cors.enabled:true http.cors.allow-origin:“*”http.cors.allow-methods:OPTIONS,HEAD,GET,POST,PUT,DELETE http.cors.allow-headers:“X-request-With,Content-Type,Content-Length,X-User”我已在配置文件中添加了上述行。我已允许。但问题依然存在。有其他选择吗?您是如何允许的?http.cors.enabled:true http.cors.allow-origin:“*”http.cors.allow-methods:OPTIONS,HEAD,GET,POST,PUT,DELETE http.cors.allow-headers:“X-Requested-With,Content-Type,Content-Length,X-User”我在配置文件中添加了上述行。