Question

How do I get the last redirected URL using Typhoeus? For instance, if I go to a Bit.ly URL, how do I get the "real" url it points to when making a request? I tried accessing response.headers_hash['Location'], but it seems to be nil for every request I am making, so I assume this is not how I should get the final location.

request = Typhoeus::Request.new(url, :timeout  => 3000, :followlocation => true)    

request.on_complete do |response|
    if response.success?
        location = response.headers_hash['Location'] #not working
        end
end
Was it helpful?

Solution

Just discovered the this gives you the final location of the redirect:

lastUrl = response.effective_url

OTHER TIPS

I used gem final_redirect_url to get the final url after single/multiple redirections.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top