title: Adding a custom header to HTTP request using angular.js
body: <p>I am a novice to angular.js, and I am trying to add some headers to a request:</p>
  
  <pre><code>   var config = {headers: {
              'Authorization': 'Basic d2VudHdvcnRobWFuOkNoYW5nZV9tZQ==',
              'Accept': 'application/json;odata=verbose'
          }
      };
  
     $http.get('https://www.example.com/ApplicationData.svc/Malls(1)/Retailers', config).success(successCallback).error(errorCallback);
  </code></pre>
  
  <p>I've looked at all the documentation, and this seems to me like it should be correct.</p>
  
  <p>When I use a local file for the URL in the <code>$http.get</code>, I see the following HTTP request on the network tab in Chrome:</p>
  
  <pre><code>GET /app/data/offers.json HTTP/1.1
  Host: www.example.com
  Connection: keep-alive
  Cache-Control: max-age=0
  If-None-Match: "0f0abc9026855b5938797878a03e6889"
  Authorization: Basic Y2hhZHN0b25lbWFuOkNoYW5nZV9tZQ==
  Accept: application/json;odata=verbose
  X-Requested-With: XMLHttpRequest
  If-Modified-Since: Sun, 24 Mar 2013 15:58:55 GMT
  User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22
  X-Testing: Testing
  Referer: http://www.example.com/app/index.html
  Accept-Encoding: gzip,deflate,sdch
  Accept-Language: en-US,en;q=0.8
  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
  </code></pre>
  
  <p>As you can see, both of the headers were added correctly. But when I change the URL to the one shown in the <code>$http.get</code> above (except using the real address, not example.com), then I get:</p>
  
  <pre><code>OPTIONS /ApplicationData.svc/Malls(1) HTTP/1.1
  Host: www.datahost.net
  Connection: keep-alive
  Access-Control-Request-Method: GET
  Origin: http://mpon.site44.com
  User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22
  Access-Control-Request-Headers: accept, origin, x-requested-with, authorization, x-testing
  Accept: */*
  Referer: http://mpon.site44.com/app/index.html
  Accept-Encoding: gzip,deflate,sdch
  Accept-Language: en-US,en;q=0.8
  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
  </code></pre>
  
  <p>The only difference in code between these two is one is for the first the URL is a local file, and for the second the URL is a remote server. If you look at the second Request header, there is no Authentication header, and the <code>Accept</code> appears to be using a default instead of the one specified. Also, the first line now says <code>OPTIONS</code> instead of <code>GET</code> (although <code>Access-Control-Request-Method</code> is <code>GET</code>).</p>
  
  <p>Any idea what is wrong with the above code, or how to get the additional headers included using when not using a local file as a data source?</p>