When I post data to a Rails 4 application with Content-Type: "application/x-www-form-urlencoded" I can get the body of the request with request.body.read
However, when I post data with Content-Type "application/json", request.body.read is blank unless I call request.body.rewind first.
Two questions:
1.) How do I get the raw request body without calling rewind on the stream first?
2.) Is it possible to stop Rails (or Rack) parsing the JSON in the request body when the client sends content-type application/json
Note that in Rails 3, like Rails 4 the parsed JSON is available in params, but request.body.read does not require rewind first.
This is indeed a bug. The fix has been integrated into master and should presumably pop up in 4.0.1.
Use request.env instead of request.body.read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With