我想解开网址,但一直没能找到代码(vb.net/c#)来做到这一点。这些是Twitter缩短的URL,我想我可以尝试访问可用的Web服务之一,并执行httpwebrequest,但希望找到一些编程方式来做到这一点。unshortening urls
回答
你可以直接从缩短网址的回应中得到它,因为它会返回一个状态码MovedPermanently
以及真实网址的位置(这对大多数网站都适用,不需要导航到真实网址)
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://t.co/xqbLEi6s");
req.AllowAutoRedirect = false;
var resp = req.GetResponse();
string realUrl = resp.Headers["Location"];
其他的测试数据:http://goo.gl/zdf2n
,http://tinyurl.com/8xc9vca
,http://x.co/iEup
,http://is.gd/vTOlz6
,http://bit.ly/FUA4YU
或者您可以允许自动重定向并从resp.ResponseUri属性获取真实URL: 'HttpWebRequest req =(HttpWebRequest)WebRequest.Create(“http://t.co/xqbLEi6s”); var resp = req.GetResponse(); string realUrl = resp.ResponseUri.AbsoluteUri;' – Yuriy 2013-10-04 08:35:01
@Yuriy为什么我应该加载整个(可能很大)的页面,当我可以做一个小的响应。 – 2013-10-04 08:54:03
我还没有想过,你是对的,你的代码更有效率。 – Yuriy 2013-10-04 12:56:05
在没有询问创建URL的服务(并且每种服务的请求方式会不同)的情况下,或者更实用地说,只需打开URL并查看其重定向到的位置,没有任何神奇的方法可以解除URL的释放。
- 1. Django urls/slugs @#!
- 2. Java和SEO URLS
- 3. Rails URLs not working
- 4. php:SEO friendly urls
- 5. Nginx的Canonical URLs
- 6. geochart region clickable urls
- 7. Google Analytics for short urls
- 8. Joomla URL re-write urls
- 9. Foreach Urls JSON解码
- 10. NoReverseMatch在/ <urls>
- 11. 清洁URLS /的.htaccess
- 12. 分享动态URLS
- 13. BlackBerry问题与urls
- 14. javascript中的Masking urls
- 15. Url Rewrite for angular urls
- 16. MediaWiki with short URLs and SSL
- 17. HTTP POST prarameters order/REST urls
- 18. Rewerite URLS的.htaccess主机
- 19. BeautifulSoup Absoute URLs Print to CSV
- 20. Get link_stats for many..MANY urls
- 21. Apache mod-rewrite for short urls
- 22. jQuery Mobile URLs未更新
- 23. Node.js和Mongoose - SEO Friendly URLs
- 24. tidhttp get procedure not working on urls
- 25. 可能的根本URLS
- 26. Spring Web Api,解析URLS
- 27. php array对于urls唯一
- 28. 的.htaccess:操纵/更改URLS
- 29. Django:ImportError at/No module named urls
- 30. 使用Ember.js的Hashbang URLs
如何使用'HttpWebRequest'访问Web服务不是编程?你写了一个程序来使用这个类,不是吗? – BoltClock 2012-03-18 17:26:01
您采取的任何方法都必须涉及对某些外部API执行查询。 – 2012-03-18 17:27:26