How can I access the original POST
message in a controller and send it back unaltered to its original sender?
Asked
Active
Viewed 2.1k times
27

joscas
- 7,474
- 5
- 39
- 59
-
What do you mean "send back"? To the browser? – Dennis Hackethal Jan 13 '13 at 17:59
-
I'm using Rails as an API. In this case, I'm sending back to the server that made the original POST for verification purposes. – joscas Jan 13 '13 at 18:05
-
Hello there! @joscas, Could you please include in this question, the code to actually SEND the request back to its sender? it'd seem that request.raw_post only gives you the thing you intend to send back, right? – jlstr Feb 11 '14 at 02:11
-
Found very few questions talking about this and thank god, I got it working now. – Satya Kalluri Jul 14 '15 at 07:05
1 Answers
60
You can use ActionDispatch::Request#raw_post
to get the unaltered POST data:
request.raw_post

Itay Grudev
- 7,055
- 4
- 54
- 86

Philip Hallstrom
- 19,673
- 2
- 42
- 46
-
Hi Philip, I looked into that link, and request.raw_post appears to be used to fetch the request content, but How do you actually send the request back to the sender? can you help me? – jlstr Feb 11 '14 at 02:15
-
3@JoseE -- `render :text => request.raw_post`. You may have to specify some headers for MIME type. If you know you're always working with a specific format (xml or json), it's better to supply that than `:text`, as in `render :json => request.raw_post`. – JellicleCat Mar 27 '14 at 14:59