0

I have a GET request setup in Postman with raw body data as below and it works. I can get data from the server enter image description here

But my Js fetch api I'm not sure how to add request body data to it. Here is my GET request config

var requestOptions = { method: 'GET', headers: myHeaders, body: raw, redirect: 'follow' }; fetch("https://example.net:/app/v1/cmp/displacer/url", requestOptions) .then(response => response.text()) .then(result => console.log(result)) .catch(error => console.log('error', error)); 

But it returns error

error TypeError: Failed to execute 'fetch' on 'WorkerGlobalScope': Request with GET/HEAD method cannot have body. 

The server only accept GET request for that URL. I tried to googled but no luck. Thank you for your time.

1

1 Answer 1

2

Sending a BODY (a.k.a. payload) in a GET request is unsupported by fetch because its behavior is undefined in HTTP and a lot of other systems don't support it or handle it in unexpected ways. If you need to send a BODY along, you should probably be using a different method than GET; If you need to send parameters with your GET request, you can try sending a query string.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.