What I really wish to do is create a new POST request add all my
arguments to it, POST it and then redirect back to my
'out_message_url(@out_message)' or index.rhtml page for this
controller.
I can see that I could use the 'redirect_to' method but it seems that
this can only send a GET request, how can I send a POST request?
Any clues how I should go about this, without having to resort to
creating a new view with a form and a POST action?
I actually tried this but I get a 'stack level too deep' error
message.
If I run the Rails console I seem to get alot of warnings about HTTP
variables already being declared, when the code hits the require 'net/
HTTP' call.
I then just put this piece of code into the
'post_to_external_url(content)' method and get the 'stack level too
deep' error:
However when I run it on its own using IRB it works no problem.
I'm not sure why I get these conflicts, and I'm not sure of a 'Rails'
way of sending new Requests from a Controller.
All I want to do is call another RESTful web service and put that
value into my model, but without going via a view.
Any suggestions will be greatly appreaciated.
Many thanks,
I actually tried this but I get a 'stack level too deep' error
message.
If I run the Rails console I seem to get alot of warnings about HTTP
variables already being declared, when the code hits the require 'net/
HTTP' call.
Where are you putting the require? What variables is it complaining
about?
I'm not sure why I get these conflicts, and I'm not sure of a 'Rails'
way of sending new Requests from a Controller.
All I want to do is call another RESTful web service and put that
value into my model, but without going via a view.
The alternative is to use an ActiveResource model to proxy the remote
RESTful model interface. Then you can access the remote data similar to
accessing a local model...
If a working example helps, see if something like this does the
trick. It basically sets up an encrypted post to https://gatewaybeta.fedex.com/xml.
url = 'gatewaybeta.fedex.com'
path = "/xml"
headers = {"Content-Type" => "text/xml"}
h = Net::HTTP.new(url, 443)
h.use_ssl = true
xmlrequest = "a bunch of xml..."
resp, data = h.post(path, xmlrequest, headers) #posts the request
From here, you can do whatever you want with the response status
(contained in the 'resp' varaible) and/or response data (contained in
the 'data' variable).
I don't know much about how this affects threading, performance, etc.,
so others should feel free to chime in if I'm doing something
horrible. (Heck, I'd appreciate knowing about it!)
Thanks so much for your help.
Mark you were right I was using require 'net/http' and this was
conflicting with my controller.
I removed the require altogether and it worked fine.
Although I had tried moving the 'require' around previously, I had
failed to notice that my Mongrel test server had crashed and so was
continually getting the 'stack too deep' error message.
Kyle thanks for that code snippet its most useful and good to see how
other people approach problems like these.