How do I get the destination URL of a shortened URL using Ruby?

前端 未结 4 2112
北荒
北荒 2021-01-04 06:59

How do I take this URL http://t.co/yjgxz5Y and get the destination URL which is http://nickstraffictricks.com/4856_how-to-rank-1-in-google/

4条回答
  •  心在旅途
    2021-01-04 07:37

    require 'net/http'
    require 'uri'
    
    Net::HTTP.get_response(URI.parse('http://t.co/yjgxz5Y'))['location']
    # => "http://nickstraffictricks.com/4856_how-to-rank-1-in-google/" 
    

提交回复
热议问题