Forum: Ruby on Rails Making an HTTP request to an external machine

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A24e589de07cb769a71f28aead957a48?d=identicon&s=25 Duane (Guest)
on 2006-06-07 20:08
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.
9d7d8ef2179661d6b30e180fa588cd45?d=identicon&s=25 Calle Dybedahl (Guest)
on 2006-06-08 09:54
(Received via mailing list)
>>>>> "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/rdo...).
--
		     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
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-06-14 00:44
(Received via mailing list)
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
This topic is locked and can not be replied to.