如何从短网址获取长网址? [英] How to get long URL from short URL?

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

问题描述

使用 Ruby,如何将短 URL(tinyURL、bitly 等)转换为相应的长 URL?

Using Ruby, how do I convert the short URLs (tinyURL, bitly etc) to the corresponding long URLs?

推荐答案

我不使用 Ruby,但总体思路是向服务器发送 HTTP HEAD 请求,服务器将返回 301 响应(永久移动)包含 URI 的 Location 标头.

I don't use Ruby but the general idea is to send an HTTP HEAD request to the server which in turn will return a 301 response (Moved Permanently) with the Location header which contains the URI.

HEAD /5b2su2 HTTP/1.1
Host: tinyurl.com
Accept: */*

回复:

HTTP/1.1 301 Moved Permanently
Location: http://stackoverflow.com
Content-type: text/html
Date: Sat, 23 May 2009 18:58:24 GMT
Server: TinyURL/1.6

这比打开实际 URL 快得多,而且您真的不想获取重定向的 URL.它还可以与 tinyurl 服务配合使用.

This is much faster than opening the actual URL and you don't really want to fetch the redirected URL. It also plays nice with the tinyurl service.

查看 ruby​​ 中的任何 HTTP 或 curl API.这应该相当容易.

Look into any HTTP or curl APIs within ruby. It should be fairly easy.

这篇关于如何从短网址获取长网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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