Hello HF,
this is my first Thread and here i would like to release my Source!
With this code you can shorten any URL to http://goo.gl/, without Captcha!
Also you can get the long URL behind the shorten one!
This is all is via Webrequest.
Enjoy the Code and please give credits to me, if you use it !
Code to shorten a long URL:
Code to get the long URL from the short one:
Thank you HF, you are so great !
~The Expert
this is my first Thread and here i would like to release my Source!
With this code you can shorten any URL to http://goo.gl/, without Captcha!
Also you can get the long URL behind the shorten one!
This is all is via Webrequest.
Enjoy the Code and please give credits to me, if you use it !
Code to shorten a long URL:
Code
Public Function shortenurl(ByVal long_uri As String)
Dim postdata As String = "{" & Chr(34) & "longUrl" & Chr(34) & ":" & Chr(34) & long_uri & Chr(34) & "}"
Dim Request As HttpWebRequest = CType(WebRequest.Create("https://www.googleapis.com/urlshortener/v1/url"), HttpWebRequest)
Request.Method = "POST"
Request.ContentType = "application/json"
Dim Post As String = postdata
Dim byteArray() As Byte = Encoding.UTF8.GetBytes(Post)
Request.ContentLength = byteArray.Length
Dim DataStream As Stream = Request.GetRequestStream()
DataStream.Write(byteArray, 0, byteArray.Length)
DataStream.Close()
Dim Response As HttpWebResponse = Request.GetResponse()
DataStream = Response.GetResponseStream()
Dim reader As New StreamReader(DataStream)
Dim ServerResponse As String = reader.ReadToEnd()
reader.Close()
DataStream.Close()
Response.Close()
Dim res As String = ServerResponse
Dim result As String = res.Split(":")(2) & ":" & res.Split(":")(3)
result = result.Substring(0, result.Length - 13)
result = result.Remove(0, 2)
Return result
End Function 'Coded by The ExpertCode to get the long URL from the short one:
Code
Public Function getlongurl(ByVal long_uri As String)
Dim web As New Net.WebClient
Dim res As String
res = web.DownloadString("https://www.googleapis.com/urlshortener/v1/url?shortUrl=" & long_uri)
Dim result As String = res.Split(":")(4) & ":" & res.Split(":")(5)
result = result.Substring(0, result.Length - 12)
result = result.Remove(0, 2)
Return result
End Function 'Coded by The ExpertThank you HF, you are so great !
~The Expert

