Send a GET request with a body in JavaScript (XMLHttpRequest) [duplicate]
No, it is not possible to send a GET request with a body in JavaScript.
it looks like the payload is simply not sent
That is correct. This is defined in the specification:
The
send(body)
method must run these steps:...
- If the request method is
GET
orHEAD
, set body to null.
Also a request via the Fetch API does not allow a body. From the specification:
- If either init["body"] exists and is non-null or inputBody is non-null, and request’s method is
GET
orHEAD
, then throw a TypeError.
The best would be if the API could be fixed.
If that is not possible, you could add a server-side script that you can use as a proxy that passes the requests to the API. You can than call this script with a GET request with the data in the URL instead of the body or using a POST request with a body. This script then can make the GET request with a body (as long as the chosen language supports it).