Fetch worker: Adding body text to my request causes 400 response

Hi,

Coding hobbyist here so apologies if this is a dumb question. I have started up a new worker instance with the default fetch setup.

It returns “hello world!” just fine until I add anything to the body of the request (I want to add JSON to the request) and as soon as I add anything (even {}) I start getting “400 Bad Request” responses. Is there a setting I need to change in order to attach body text to my requests?

I am not publishing just running on my local machine. Also, I’ve set content-type headers for application/json.

It’s hard to answer this without seeing your code - so, best to share it. You can even use the playground to replicate and share a link:

https://developers.cloudflare.com/workers/learning/playground/

1 Like

Thanks Simon - You helped me without realising it! When I went to the playground I realised my mistake was leaving the request type as GET rather than POST. Cloudflare doesn’t like GET requests with a body… which makes sense. Thanks for the suggestion.

1 Like

Nice one - glad to hear you got things working :slight_smile: .

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.