Dmitriy Polovinkin Dmitriy Polovinkin - 1 year ago 138
Ruby Question

how send post request and open url in Ruby Sinatra

i am sending a post request,
and need to get result like with html form,
where we going to some url after doing request

<form action="url" method="post">

i tried this:

return response.body()

and i get only body of html page,
but i need to redirect to this page.
what right way to go to needed URL?

here my code for post request:

post '/send' do
uri = URI.parse("")
response = Net::HTTP.post_form(uri, {
"WMI_MERCHANT_ID" => "xxx",
"WMI_PAYMENT_AMOUNT" => "10.00",
"WMI_CURRENCY_ID" => "643"

Answer Source

If you want to directly pass along a POST request and redirect to it, you can do

post '/send' do
  redirect <your_url>, 307

307 is the HTTP status code to not modify the request method.

Handle a redirect response like this:

post '/send' do
  # post form
  redirect response['location'], 302
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download