Call us now on 01772 217800

XML API Sample Code (VB.Net)



Tagged with code sample, vb, visual basic, XML API, SEND_SMS, CHECK_BALANCE
by Paddy Green
in Code Samples

24-Oct-2014 00:00



Here is an example function for calling the XML API with Visual Basic .NET

Visual Basic .NET Calling XML API ------------------------------------------------------------------------------------------------------------------------------- Public Sub SendMessage(phone as string, message as string) 'sends a message to a single phone number Dim xml as string = "<campaign>" & _ " <header uid='[USERID]' pwd='[PASSWORD]' action='SEND_SMS'/>" & _ " <body>" & _ " <msisdn>" & phone & "</msisdn>" & _ " <msg>" & message & "</msg>" & _ " <orig>[OPTIONAL ORIGINATOR, OMIT ENTIRELY TO USE ACCOUNT ORIGINATOR]</orig>" & _ " </body>" & _ "</campaign>" Response.Write(CallXMLAPI(xml)) End Sub Public Sub CheckBalance() 'checks your balance on the system Dim xml as string = "<campaign>" & _ " <header uid='[USERID]' pwd='[PASSWORD]' action='CHECK_BALANCE'/>" & _ " <body>" & _ " </body>" & _ "</campaign>" Response.Write(CallXMLAPI(xml)) End Sub Public Shared Function CallXMLAPI(ByVal in_xml As String) As String Dim pageURL As String = "https://textgoto.com/api/xmlapi.aspx" Dim send_stream As String = "" Try send_stream = in_xml pageURL = base Dim request As HttpWebRequest = WebRequest.Create(pageURL) request.Method = "POST" request.ContentType = "text/plain" request.Timeout = 1000000 Dim writer As New StreamWriter(request.GetRequestStream()) writer.Write(send_stream) writer.Close() Dim resp As HttpWebResponse = request.GetResponse() Dim reader As New StreamReader(resp.GetResponseStream) output = reader.ReadToEnd() Catch ex As Exception output = ex.Message End Try Return output End Function