2

I am sending body in GET request in sails.js framework which internally uses express.js

curl -u username:password -i -H "Accept: application/json" -X GET -d "msisdn=32323" http://localhost:9000/api/v1.1/buy/voucher/raj/32323

i am trying to get the value of msisdn in req.body of express but it is giving me undefined.

I read on internet and it says we can send body in GET request. You can refer this stackoverflow thread. HTTP GET with request body

Community
  • 1
  • 1
selftaught91
  • 5,521
  • 3
  • 13
  • 22
  • While it's possible it's also not recommended. Either use POST or change URL to ..../buy/voucher?raj=32323 – Molda May 20 '16 at 07:13
  • my java rest server accepts body in GET request . When i am trying with curl request directly to java server it is working fine. But when i use a proxy server made with express.js I can't recieve the body – selftaught91 May 20 '16 at 07:32

1 Answers1

1

With Express it's not possible to send a body with a GET request. http://expressjs.com/en/api.html#req.body.

In reality, you shouldn't even want this Specification. If you want to send data with your GET request, query parameters will suffice, if you have the need to send data securely you shouldn't even want to use a GET request in the first place.

Lars de Bruijn
  • 1,370
  • 9
  • 15