title: How to send a correct authorization header for basic authentication
body: <p>I am trying to POST data from my API but I can't pass the basic authentication.</p>
  <p>I try:</p>
  <pre><code>$.ajax({
    type: 'POST',
    url: http://theappurl.com/api/v1/method/,
    data: {},
    crossDomain: true,
    beforeSend: function(xhr) {
      xhr.setRequestHeader('Authorization', 'Basic [REDACTED]');
    }
  });
  </code></pre>
  <p>My server configuration response is:</p>
  <pre><code>response[&quot;Access-Control-Allow-Origin&quot;] = &quot;*&quot;
  response[&quot;Access-Control-Allow-Methods&quot;] = &quot;POST&quot;
  response[&quot;Access-Control-Max-Age&quot;] = &quot;1000&quot;
  response[&quot;Access-Control-Allow-Headers&quot;] = &quot;*&quot;
  </code></pre>
  <p>The headers that I get is:</p>
  <p><strong>Request Headers</strong></p>
  <pre><code>OPTIONS /api/v1/token-auth/ HTTP/1.1
  Host: theappurl.com
  Connection: keep-alive
  Access-Control-Request-Method: POST
  Origin: http://127.0.0.1:8080
  User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31
  Access-Control-Request-Headers: origin, authorization, content-type
  Accept: */*
  Referer: http://127.0.0.1:8080/
  Accept-Encoding: gzip,deflate,sdch
  Accept-Language: es,en;q=0.8
  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
  </code></pre>
  <p><strong>Response header</strong></p>
  <pre><code>HTTP/1.1 401 Unauthorized
  Server: nginx/1.1.19
  Date: Fri, 16 Aug 2013 01:29:21 GMT
  Content-Type: text/html
  Content-Length: 597
  Connection: keep-alive
  WWW-Authenticate: Basic realm=&quot;Restricted&quot;
  </code></pre>
  <p>I guess the server configuration is good because I can access to API from the <em><a href="https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo" rel="noreferrer">Advanced REST Client</a></em> (Chrome Extension)</p>
  <p>Any suggestions?</p>
  <p>PD:
  The header that I get from Advanced REST client is:</p>
  <pre><code>    User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31
      Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
      Authorization: Basic [REDACTED]
      Content-Type: application/x-www-form-urlencoded 
      Accept: */*
      Accept-Encoding: gzip,deflate,sdch
      Accept-Language: es,en;q=0.8
      Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
  </code></pre>
  <p>and</p>
  <pre><code>    Server: nginx/1.1.19 
      Date: Fri, 16 Aug 2013 01:07:18 GMT 
      Content-Type: application/json; charset=utf-8 
      Transfer-Encoding: chunked 
      Connection: keep-alive
      Vary: Accept, Cookie 
      Allow: POST, OPTIONS 
      X-Robots-Tag: noindex
  </code></pre>
  <p>sending OPTION method</p>