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.
When I try building a query with XMLHttpRequest
, 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):
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))
Libraries such as axios are built on XMLHttpRequest, so they are not working either...
Is there any way to achieve this in JavaScript?