title: Send a GET request with a body in JavaScript (XMLHttpRequest)
body: <p>I have to interact with an API that takes parameters from the body of a GET request. I know this might not be the best idea, but it is the way the API was built. </p>
  
  <p>When I try building a query with <code>XMLHttpRequest</code>, it looks like the payload is simply not sent. You can run this and look in the network tab; the request is sent, but there is no body (tested in latest Chrome and Firefox):</p>
  
  <pre class="lang-js prettyprint-override"><code>const data = {
    foo: {
      bar: [1, 2, 3]
    }
  }
  const xhr = new XMLHttpRequest()
  xhr.open('GET', 'https://my-json-server.typicode.com/typicode/demo/posts')
  xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8')
  xhr.send(JSON.stringify(data))
  </code></pre>
  
  <p>Libraries such as axios are built on XMLHttpRequest, so they are not working either...</p>
  
  <p>Is there any way to achieve this in JavaScript? </p>