title: React remote request with authorization
body: <p>I want to do a remote request using React JS. I try to do it as follows:</p>
  
  <pre><code>let username = 'some-username';
  let password = 'some-password';
  let url = 'some-url';
  fetch(url', {
      method: 'GET',
      headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Basic '+btoa(username + ":" + password),
      },
  }).then(response =&gt; {
        debugger;
        return response.json();
  }).then(json =&gt; {
        debugger;
  });
  </code></pre>
  
  <p>I get an error:
  <a href="https://i.stack.imgur.com/UEyC5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UEyC5.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/gGRRy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gGRRy.png" alt="enter image description here"></a></p>
  
  <p>If I do the same request with the same credentials with postman it works:</p>
  
  <p><a href="https://i.stack.imgur.com/0ZkMd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0ZkMd.png" alt="enter image description here"></a> </p>
  
  <p>Any idea?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>let user = 'some-user';
  let password = 'some-password';
  let url = 'some-url';
  
  let req = new XMLHttpRequest();
  let body = '';
  
  if ('withCredentials' in req) {
      req.open('GET', url, true);
      req.setRequestHeader('Content-Type', 'application/json');
      req.setRequestHeader('Authorization', 'Basic '+ btoa(user + ":" + password));
      req.setRequestHeader('Access-Control-Allow-Origin', 'http://localhost:3000');
  
      req.onreadystatechange = () =&gt; {
          debugger;
          if (req.readyState === 4) {
              ///////////////// it comes here but req.status is 0
              if (req.status &gt;= 200 &amp;&amp; req.status &lt; 400) {
                  debugger;
                  // JSON.parse(req.responseText) etc.
              } else {
                  // Handle error case
              }
          }
      };
      req.send(body);
  }
  </code></pre>
  
  <p>This is what I see in network tab:</p>
  
  <p><a href="https://i.stack.imgur.com/zlaX2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zlaX2.png" alt="enter image description here"></a></p>