Hi all, this may sound basic, but I’m not able to figure out how to
initiate an http post action from within a controller.
What I’m trying to do is use a def function in one of my application
controllers to send a post on to another URI (using the http POST
method) that is not on my server.
I tried post(path, parameters=nil, headers=nil) but only got an error
message saying post method not found.
I also tried a redirect, but it seems this method only wants to initiate
http GET actions.
What I’m trying to do is use a def function in one of my
application controllers to send a post on to another URI
(using the http POST
method) that is not on my server.
You’re going to want to look at the net/http and/or mechanize libraries
for that.
I also tried a redirect, but it seems this method only wants
to initiate http GET actions.
Do you mean you want your response to the originating client to cause it
to issue a POST request to an arbitrary URL? You can’t do that. You can
have the rails app issue a POST request, but you can’t force the
originating client to do so.
What I’m trying to do is use a def function in one of my
application controllers to send a post on to another URI
(using the http POST
method) that is not on my server.
You’re going to want to look at the net/http and/or mechanize libraries
for that.
I also tried a redirect, but it seems this method only wants
to initiate http GET actions.
Do you mean you want your response to the originating client to cause it
to issue a POST request to an arbitrary URL? You can’t do that. You can
have the rails app issue a POST request, but you can’t force the
originating client to do so.
donald
Thanks Don. No, I don’t want my response to the originating client to
cause it to issue a POST request to an arbitrary URL? All I want to do
is generate an HTTP POST (to another URL from within the controller –
as opposed to presenting a form to a user and waiting for the user click
a submit button. For example, my application has a form that when
submitted posts data to a third party shopping cart application. When
users are in that application, they can hit a “continue shopping” button
which generates a GET request to my application. Instead of actually
showing the user a catalog, I simply want to catch the GET request and
automatically generate a POST back to the third party shopping cart
application.
I’ll do as you suggest and take a look at net/http library.
Thanks again,
Doug
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.