During one of my controller actions I want to call an external machine before I do anything. It''s not a real web service, more like a REST-style thing where I''ll just be tweaking a servlet running on another machine and sending it some data. Does Rails give me anything to work with for doing that? I read the web service stuff but it''s overkill for what I need. I just need to open up an http connection, send some data, and then check to see what response I got back. -- Posted via http://www.ruby-forum.com/.
Calle Dybedahl
2006-Jun-08 07:51 UTC
[Rails] Making an HTTP request to an external machine
>>>>> "Duane" == Duane <dmorin@gmail.com> writes:> Does Rails give me anything to work with for doing that? I read the > web service stuff but it''s overkill for what I need. I just need to > open up an http connection, send some data, and then check to see > what response I got back.Rails doesn''t, since that''s already in Ruby''s standard library. Look at Net::HTTP (http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html). -- Calle Dybedahl <calle@cyberpomo.com> http://www.livejournal.com/users/cdybedahl/ "Now I want to hear the GPL done as a Gregorian chant. Or maybe a rapper''s interpretation of the BSD license." -- Russ Allbery, BofhNet
On Jun 8, 2006, at 12:51 AM, Calle Dybedahl wrote:> "Duane" == Duane <dmorin@gmail.com> writes: > >> Does Rails give me anything to work with for doing that? I read the >> web service stuff but it''s overkill for what I need. I just need to >> open up an http connection, send some data, and then check to see >> what response I got back. > > Rails doesn''t, since that''s already in Ruby''s standard library. Look > at Net::HTTP (http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/ > index.html).open-uri is easier. require ''open-uri'' open ''http://example.com/service/endpoint?param=value'' do |fp| # ... fp is an IO-like object end -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com