' VB.NET Private Function Shorten(url As String, xml As Boolean) As String url = Uri.EscapeUriString(url) Dim reqUri As
String ="http://1click.at/api.php?action=shorturl&url={0}&format={1}" If (xml) Then reqUri = String.Format(reqUri, url, "xml")
Else reqUri =String.Format(reqUri, url, "simple") End If Dim req As HttpWebRequest = DirectCast(WebRequest.Create(reqUri), HttpWebRequest)
req.Timeout = 5000 Dim stmAs Stream = req.GetResponse().GetResponseStream() If xml Then Dim doc As New XmlDocument() doc.Load(stm)
' error checking for xml If doc("result")("statusCode").InnerText <> "200" Then Throw New WebException(doc("result")("statusCode").InnerText)
End If Return doc("result")("shorturl").InnerTextElse ' Simple Using reader As New StreamReader(stm) Return reader.ReadLine() End Using End If End Function