How to read POST information in Rails?

I would like to know how to send and receive information through HTTP POST requests.

I am using Ruby v.1.8.7 and rails v.2.3.8.

EDIT:

My action code is as follows:

require 'net/http'

# get the url that we need to post to
url = URI.parse('http://localhost:3000/ipn/payments')

xml_notificaciones = "<NOTIFICACION><TIPONOTIFICACION>1</TIPONOTIFICACION><OPERACIONES><OPERACION><TIPO>1</TIPO><ID>31548</ID></OPERACION><OPERACION><TIPO>1</TIPO><ID>XA5547</ID></OPEARACION></OPERACIONES></NOTIFICACION>"

# build the params string
post_args1 = { 'NOTIFICACION' => xml_notificaciones }
# send the request
resp, data = Net::HTTP.post_form(url, post_args1)

When I execute the above code, the page will load for a while until I get the message execution expired.

I have a route record for http://localhost:3000/ipn/paymentsurl and the following:

map.received_ipn_payments '/ipn/payments', :controller => 'payments', :action => 'parse_received_data', :method => :post

I have it raise params.inspect, so I know when it works, but nothing so far ...

+3
source share
3 answers

rails ? webrick/mongrel, . , , ( ), .

, , , /. /, GET .

: , ( , ) . , , webrick/mongrel. .

+2

, config/routes.rb. . . , , params.

... andrea, Typhoeus gem, HTTP-. , , .

+2

To receive a request for sending, you only need to create an action in the controller and set the routes using the method message.

to send a request you can use something like this

require 'net/http'
# get the url that we need to post to
url = URI.parse('http://www.url.com/subscribe')# build the params string
post_args1 = { 'email' => params[:email] }
# send the request
resp, data = Net::HTTP.post_form(url, post_args1)
+1
source

Source: https://habr.com/ru/post/1786550/


All Articles