Hi,

I have an URL I want to access in a ruby program with the addition of
posting some form data to it afterwards. The problem, though, is that
I have to post the form data to the new URL that I get refered to when
opening the one mentioned above. Like this:

--- cut ---
hostName = "some.nice.web.server"
cgiURL = "/cgi-bin/this.is.the.start.page"
postPath = "/FORMC1"

begin
  host = Net::HTTP.new( hostName, 80)
  resp, data = host.get( cgiURL, nil) # (1)
rescue
  puts "Booh. An exception. Type: "
  puts $1.type
end

# now some magic to retrieve the hostname and port resulting out of (1)
# store both in newHostName and newPortNr

begin
  postHost = Net::HTTP.new( newHostName, newPortNr)
  resp, data = postHost.get( postPath, nil)
rescue
  puts "Just another exception. Type: "
  puts $1.type
end
... post data using "postHost.post( postPath, { ...}) ...
--- cut ---

The obvious problem is expressed by the comment lines. Class
HTTPResponse does not provide access to the "current" host name and
port number.

In case it helps: In Perl that can be achieved by something along the
line of:

--- cut ---
$url = "http://some.nice.web.server/cgi-bin/this.is.the.start.page";
$ua = new LWP::UserAgent;
$req = new HTTP::Request 'GET' => "$url";
$res = $ua->request($req);
$uri = $res->base();
$strurl = $uri->as_string();
--- cut ---

Any hints or pointers are much appreciated.

    Roland