Re: [whatwg/fetch] Request with GET/HEAD method cannot have body. (#551)

> I tried using `fetch` and `node-fetch` to make GET with a request body, but it fails with:
> 
> ```
> Request with GET/HEAD method cannot have body
> ```
> 
> ### Workaround for Nodejs runtimes (not in browser ... JS on the server)
> Unfortunately the API I'm working with I cannot change at this time so I needed a work around. You can use the [axios library](https://www.npmjs.com/package/axios) to make GET with request body's
> 
> ```js
> // only works in node / server -- i have not tried in the browser
> const res = await axios.get("/api/devices", { 
>   data: { deviceName: 'name' } 
> }) 
> ```

It will not work in browser because the available APIs don't allow it.

Also note that on some operating systems it won't work because the underlying HTTP implementation does not allow it. IIRC that includes iOS and Windows.

In theory you could implement an HTTP client from scratch using lower level network APIs and guarantee the ability to have a body in GET requests... But still can't do this in browser because such low level APIs are not available.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/551#issuecomment-1238413021
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/issues/551/1238413021@github.com>

Received on Tuesday, 6 September 2022 16:54:56 UTC