Follow uri redirect


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


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

require ‘uri’
require ‘net/http’

url = “…”

max_follow = 5
uri = URI.parse(url)
response = nil
Net::HTTP.start(, 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