Follow uri redirect

Hi,

I am trying to get an uri redirection but I am getting the same uri
despite the fact that a web browser redirect to another uri
this is the code:
object_uri = openurl(url)
redirect = object_uri.base_uri.to_s
p redirect

is there another way to get the redirect uri
regards,

Hi,

I’m not sure but open-uri may follow the redirection.

I am using net/htp class to follow the URL redirection. An sample code
is

require ‘uri’
require ‘net/http’

url = “http://sample.com/…”

max_follow = 5
max_follow.times{
uri = URI.parse(url)
response = nil
Net::HTTP.start(uri.host, uri.port) {|http|
response = http.head(uri.request_uri)
}
break unless response.key?(“Location”)
url = response[‘Location’]
}

Thank you.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs