K
K
Kir Shatrov2011-02-05 13:11:38
ruby
Kir Shatrov, 2011-02-05 13:11:38

Page redirect, get url with ruby

I have an address: site.com/?foo=bar
When I go to it, the server returns the Location HTTP header with a redirect to the second address, for example site.com/products/foo_id/bar_id

I only know the original one (http://site.com/ ?foo=bar), how can I use Ruby to find out the address where he redirects?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mardy_bum, 2011-02-05
@RazoR_Empire

require 'open-uri'

puts open('http://site.com/?foo=bar').base_uri.to_s

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question