C# 实现对微博短网址的重定向还原
2013-07-24 09:46
204 查看
新浪微博中,为了节省输入字数,通过短网址对发布微博中链接进行重定向。我们可以通过代码实现对短网址进行还原,代码如下:
private string GetOrignalLink(string link) { using (WebClient client = new MyWebClient()) { client.Headers.Add("Referer", link); Stream stream = null; try { stream = client.OpenRead(link); return client.ResponseHeaders["Location"]; } catch (Exception) { throw; } finally { if (stream != null) stream.Close(); } } } internal class MyWebClient : WebClient { protected override WebRequest GetWebRequest(Uri address) { HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address); request.AllowAutoRedirect = false; return request; } }
相关文章推荐
- 微博缩短网址的实现
- ASP.NET MVC5 实现网址伪静态用c#中的WebBr用c#中的WebBrowser抢小米F码,抢小米手机以及自动测试实现原理用c#中的WebBrowser抢小米F码用c#中的WebBrowser抢小米F码,抢小米手机以及自动测试实现原理
- 博客开发手记1 – 不能发布URL长度超过280字符微博的解决方案(C#实现)
- 微博URL短网址生成算法原理及(java版、php版实现实例)
- C#实现Ping功能|根据网址查询IP
- 微博URL短网址生成算法原理及(java版、php版实现实例)
- C#实现类似新浪微博长URL转短地址的方法
- 微博缩短网址的实现
- ASP.NET(c#)中实现获取当前网站的域名网址
- 【转】微博URL短网址生成算法原理及(java版、php版实现实例)
- C#实现自动识别URL网址的方法
- 微博URL短网址生成算法原理及(java版、php版实现实例)
- 微博缩短网址是如何实现的
- C#实现Ping功能|根据网址查询IP
- C#实现Ping功能|根据网址查询IP
- C# Who Is 查询 理论实现
- IOS开发学习笔记031-代码实现微博界面
- 根据网址把图片下载到服务器C#代码
- c# 使用sharppcap实现 网络抓包