如何使用Ruby获取缩短的URL的目标URL? [英] How do I get the destination URL of a shortened URL using Ruby?

查看:122
本文介绍了如何使用Ruby获取缩短的URL的目标URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取该URL http://t.co/yjgxz5Y 并获取目标URL是 http://nickstraffictricks.com/4856_how-to-rank-1-在Google/

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/

推荐答案

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/" 

这篇关于如何使用Ruby获取缩短的URL的目标URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆