Demystifying Tiny URL’s

Ok so one of the annoying things that i have noticed with twitter is that people tend to shrink their URL’s , this is a valid point because you are limited in what you can actually put into each of your status updates.

But what happens when people start abusing this (as seen in the SA blog awards) where they hide auto accept functions into the URL. You not knowing any better click on it and are sent to a site where you automatically accept something you did not want to accept. Now while i know there are services to prevent this , i needed a way to do this via code and now i present you with a simple soloution.

private static Uri GetRedirectURL(String url)
{
HttpWebResponse response = null;
try
{
// create the request
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
// instruct the server to return headers only
request.Method = “HEAD”;
// make the connection
response = request.GetResponse() as HttpWebResponse;
// get the headers
return response.ResponseUri;
}
catch
{
throw;
}

finally
{
// make sure the response gets closed
//  this avoids leaking connections
if (response != null)
{
response.Close();
}
}
}

Using this method is simple enough , pass in the tinyURL and it will return the long URL. I am sorry about the formatting but for the life of me i could not get it to format correctly.

As always let me know what you think.

~stalkerh

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

One Comment to “Demystifying Tiny URL’s”

  1. name 29 July 2009 at 4:06 pm #

    I like it so much,


Leave a Reply