解决方法
这里有两种方法,使用
HTTPClient和
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/