0

I have an Express GET route to fetch all users. Whenever a req.body is present, the server is always responding with 400.

Obviously, I have body-parser and this behaviour is only experienced in the production k8s environment (working fine in localhost)

Is there any limitation to send req.body to GET routes? Express documentation doesn't say so

Adiii
  • 54,482
  • 7
  • 145
  • 148
bmnidhin
  • 56
  • 10
  • 2
    Potentially proxy/middleware may just not propagate it, as it's not standard: https://stackoverflow.com/a/978094/1075282 – Renat Aug 20 '22 at 11:47

1 Answers1

0

You need to set the content type --header "Content-Type: application/json" in the GET request and it should work.

 curl --header "Content-Type: application/json"   --request GET  --data '{"username":"xyz","password":"xyz"}' https://example.com/posttest

and here is the nodejs snippet

app.get('/posttest', function(req, res){
  console.log("posttest call received")
  res.send(req.body);
});

enter image description here

Adiii
  • 54,482
  • 7
  • 145
  • 148