If http://foo.com
redirects to 1.2.3.4
which then redirects to http://finalurl.com
, how can I use Ruby to find out the landing URL "http://finalurl.com"?
相关问题
- Stop .htaccess redirect with query string
- IPAddress.[Try]Parse parses 192.168 to 192.0.0.168
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
相关文章
- How to get jQuery.ajax response status?
- send redirect and setting cookie, using laravel 5
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- Segmentation fault with ruby 2.0.0p247 leading to
- RMI Threads prevent JVM from exiting after main()
Here's two ways, using both HTTPClient and Open-URI:
Another way, using Curb:
I'm not much of a Ruby user, but what you basically need is something to interpret HTTP headers. The following library appears to do that:
http://www.ensta.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html
Skip down to "following redirection."
for
JRuby
this workedI have implemented a RequestResolver for my need:
https://gist.github.com/lulalala/6be104641bcb60f9d0e8
It uses Net::HTTP, and follows multiple redirects. It also handles relative redirects. It was for my simple need so may have bugs. If you discover one please tell me.