title: How to pass basic authentication in rest service in AngularJS?
body: <p>I have a REST web service that requires a basic authentication to consume its data. I am consuming it in AngularJS. </p>
  
  <p>The way I am doing it is as follows:</p>
  
  <pre><code>$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;
  
          });       
  }]);
  </code></pre>
  
  <p>But the error that I am having in the console is: </p>
  
  <blockquote>
    <p>Request header field headers is not allowed by
    Access-Control-Allow-Headers in preflight response.</p>
  </blockquote>
  
  <p>Can someone help to resolve this issue? Note that I have tested it on postman, and it works fine, returning me all data correctly.</p>