If you’re a frequent Twitter user, we’ve all had the problem of space limitations due to long Urls since the length of the text message is 140 characters. If you don’t know about it yet, then there is a solution available!
TinyUrl.com
Ever heard of TinyURL.com? Well, basically, it’s a redirection service that gives you a short Url for your given your destination Url, which you can use in your web pages or emails. It has served many different purposes for years.
Typical reasons for its use to to shorten the Urls that are not only long enough to accommodate in limited spaces, it’s unlikely that users would be able to reproduce the long urls exactly by typing it without errors.
For example,
In Twitter, small Urls are preferred due to space limations
In emails blasts where long urls often get malformed and become non-functional. Tinyurls serve a good replacement for long urls.
For (casual) anonymity to users, such as for hiding affiliate links etc Tinyurls are mostly used.
TinyURL.com does not require you to create an account before starting with creating short urls. Just fill up the form with the long url and press the ‘Make TinyURL!’ button and instantly you get a short url that you can use in place of your given url. TinyURL now also allow an optional alias for your url which you can use to point to your page, given that the alias is not already taken.
So, the short link to an inventory page on one of our dealers (http://www.reedmantoll.com/new-inventory/vehicle-details.htm?vehicleId=75a132e44046381e01cc7e90761a4815&useHistory=true) is as small as http://tinyurl.com/422nlt!
That was all about TinyURL that most of you might have already known. Many developers wished if they could find a way to create TinyURLs without manually typing them, from within their online applications is actually quite easy to do in VB.NET.
It turns out that there is an API available and to make a request it’s as simple as calling a page as below.
http://tinyurl.com/api-create.php?url=
The output you get contains just one line containing the TinyURL corresponding to the url that you passed. I have already started using this API and am sure you are not far behind!
Here is an example using VB.NET:
Private Function generateTinyUrl(ByVal url As String)
Dim tinyUrlQuery As String = "http://tinyurl.com/api-create.php?url=" + url
Dim tinyUrl As String = LTrim(RTrim(GetHTMLPage(tinyUrlQuery)))
Return tinyUrl
End Function
Public Function GetHTMLPage(ByVal URL As String, _
Optional ByVal TimeoutSeconds As Integer = 5, _
Optional ByVal proxy As Integer = -1) _
As String
' Retrieves the HTML from the specified URL,
' using a default timeout of 10 seconds
Dim objRequest As Net.WebRequest
Dim objResponse As Net.WebResponse
Dim objStreamReceive As System.IO.Stream
Dim objEncoding As System.Text.Encoding
Dim objStreamRead As System.IO.StreamReader
Try
' Setup our Web request
objRequest = Net.WebRequest.Create(URL)
objRequest.Timeout = TimeoutSeconds * 1000
' Retrieve data from request
objResponse = objRequest.GetResponse
objStreamReceive = objResponse.GetResponseStream
objEncoding = System.Text.Encoding.GetEncoding( _
"utf-8")
objStreamRead = New System.IO.StreamReader( _
objStreamReceive, objEncoding)
' Set function return value
GetHTMLPage = objStreamRead.ReadToEnd()
' Check if available, then close response
If Not objResponse Is Nothing Then
objResponse.Close()
End If
Catch ex As Exception
' Error occured grabbing data, simply return nothing
' MessageBox.Show(ex.ToString)
Return "Exception"
End Try
End Function