title: Navigate to URL with custom request headers in JavaScript
body: <p>Question just like the title.</p>
  
  <p>In command line, we can type:</p>
  
  <pre><code>curl -H "header_name: header_value" "http://example"
  </code></pre>
  
  <p>to navigate to <a href="http://example" rel="nofollow noreferrer">http://example</a> with a custom request header as shown above.</p>
  
  <p>Q: If I need to write a JavaScript to do the same thing, how should I do?</p>
  
  <pre><code>var url = 'https://example';
  var myRequest = new XMLHttpRequest();
  myRequest.open('GET', url ,false);
  myRequest.setRequestHeader('header-name','header-value');
  myRequest.send();
  </code></pre>
  
  <p>I tried this code, there is no syntax error but the page didn't change. Hence, I don't really know if I modified the request header(s).</p>