How can I get the final URL after redirects using Ruby?

前端 未结 5 1811
执念已碎
执念已碎 2020-12-17 10:35

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 \"h

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 11:15

    Another way, using Curb:

    def get_redirected_url(your_url)
      result = Curl::Easy.perform(your_url) do |curl|
        curl.follow_location = true
      end
      result.last_effective_url
    end 
    

提交回复
热议问题