If http://foo.com redirects to 1.2.3.4 which then redirects to http://finalurl.com, how can I use Ruby to find out the landing URL "http://finalurl.com"?
http://foo.com
1.2.3.4
http://finalurl.com
Here's two ways, using both HTTPClient and Open-URI:
require 'httpclient' require 'open-uri' URL = 'http://www.example.org' httpc = HTTPClient.new resp = httpc.get(URL) puts resp.header['Location'] >> http://www.iana.org/domains/example/ open(URL) do |resp| puts resp.base_uri.to_s end >> http://www.iana.org/domains/example/
2.1m questions
2.1m answers
60 comments
57.0k users