Making an HTTP request to an external machine

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.

“Duane” == Duane [email protected] 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 D. <[email protected]>
	 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 D. wrote:

“Duane” == Duane [email protected] 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 H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com