title: How to set username and password in axios get method header
body: <p>I want to fetch some data from a server via axios in my react project. When i put the url on browser and hit enter browser ask me username and password and after that, i can see the json data. But i dont know how to set the password and username in axios header in a get method. I have searched it in many forums and pages,especially this link didin't help me: <a href="https://stackoverflow.com/questions/45316243/sending-axios-get-request-with-authorization-header">Sending axios get request with authorization header</a> . So finally i tried (many things before this, but i was more confused): </p>
  
  <pre><code>componentDidMount() {
     axios.get('http://my_url/api/stb', {auth: {
      username: 'usrnm',
      password: 'pswrd'
  }})
     .then(function(response) {
         console.log(response.data);
         console.log(response.headers['Authorization']);
     }).catch(err =&gt; console.log(err));
  }
  </code></pre>
  
  <p>And i can not get anything. I get this error in console:</p>
  
  <pre><code>Error: Network Error
  Stack trace:
  createError@http://localhost:3000/static/js/bundle.js:2195:15
  handleError@http://localhost:3000/static/js/bundle.js:1724:14
  </code></pre>
  
  <p>Actually, the api documentation mentioned that with these words:</p>
  
  <blockquote>
    <p>If there is no header or not correct data - server's answer will
    contain HTTP status 401 Unauthorized and message:</p>
  </blockquote>
  
  <pre><code>&lt; {"status":"ERROR","results":"","error":"401 Unauthorized request"}
  </code></pre>
  
  <blockquote>
    <p>For successful authentification is sufficient to add in every request
    header to the API:</p>
  </blockquote>
  
  <pre><code>Authorization: Basic &lt;base64encode("login":"password")&gt;
  </code></pre>
  
  <p>The weird thing is, when i use postman, the response send me a "401 unauthorized" response below the body section. But i can not see any 401 errors in browser's console.</p>