The following code is a VBScript example of sending a message using XML.
<%@ language="VBScript" %><%Option Explicit'************************************************************************
**********' Sample SMS API XML Interface example in VBScript/ASP' Copyright Mediaburst 2010'' IMPORTANT NOTE:' This script is a brief example and should not be used in a live
environment' This example does not include any error checking or error handling,' error handling must be added before use in a live environment.' This script is provided without warranty and Mediaburst do not offer' any support in the use of this example.'************************************************************************
**********' Variable declarationDim httpConn, responseDoc, serverURL, username, password, originator,
content, clientid' XML variablesDim sendDoc, xmlDecl, msgNode, userNode, passNode, proxyURLserverURL = "http://sms.message-platform.com/xml/send.aspx"'************************************************************************
**********' Proxy Server URL - Leave as blank string if not required' This is only supported if using MSXML version 6' e.g. proxyURL = "http://1.2.3.4:3128"proxyURL = ""' Set your account details here' API Account Usernameusername = "my_user"' API Account Passwordpassword = "my_pass"' Message originator (from)originator = "MB_ASP"' Message Contentcontent = "Hello, this is a test message from my ASP script"' Client ID / Job IDclientID = "123456"' This array is just for example purposes, normally you would supply
destination addressesDim destAddrs(1)destAddrs(0) = "441234567890"destAddrs(1) = "449876543210"'************************************************************************
**********' Create an XML Document object - Might have to change this depending
upon version of MSXML installed' This will also need changing at line 96 where it creates
MSXML2.ServerXMLHTTP.6.0' Version 2.x use Msxml.DOMDocument' Version 3.0 use Msxml2.DOMDocument.3.0' Version 4.0 use Msxml2.DOMDocument.4.0' Version 6.0 use Msxml2.DOMDocument.6.0Set sendDoc = Server.CreateObject("Msxml2.DOMDocument.6.0")' Create an XML declaration at the top of the documentSet xmlDecl = sendDoc.createProcessingInstruction("xml", "version='1.0'")sendDoc.appendChild xmlDeclSet msgNode = sendDoc.createElement("Message")Set sendDoc.documentElement = msgNodeSet userNode = sendDoc.createElement("Username")Set passNode = sendDoc.createElement("Password")userNode.nodeTypedValue = usernamepassNode.nodeTypedValue = passwordmsgNode.appendChild userNodemsgNode.appendChild passNode' Loop round the following section for each SMS you want to sendDim anAddr ' single destination addressfor each anAddr in destAddrs' Create NodesDim smsNode, toNode, contentNode, fromNode, idNodeSet smsNode = sendDoc.createElement("SMS")Set toNode = sendDoc.createElement("To")Set contentNode = sendDoc.createElement("Content")Set fromNode = sendDoc.createElement("From")Set idNode = sendDoc.createElement("ClientID")' Assign valuestoNode.nodeTypedValue = anAddrcontentNode.nodeTypedValue = contentfromNode.nodeTypedValue = originatoridNode.nodeTypedValue = clientID' Append nodes to SMS nodesmsNode.appendChild toNodesmsNode.appendChild contentNodesmsNode.appendChild fromNodesmsNode.appendChild idNode' Append SMS node to main documentmsgNode.appendChild smsNodenext' End of loop' Create HTTP Connection ObjectSet httpConn = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")' Optionally setup a proxy serverIf (proxyURL <> "") ThenhttpConn.setProxy 2, proxyURLEnd If' Open synchronous connectionhttpConn.open "POST", serverURL, falsehttpConn.setRequestHeader "Content-type","text/xml"httpConn.Send sendDoc.xmlIf(httpConn.status = 200) Then' Load the response into an XML DOM Document objectset responseDoc = httpConn.responseXMLDim respNode, genErrNo, genErrDescFor each respNode in responseDoc.documentElement.childNodesSelect Case respNode.nodenameCase "ErrNo"genErrNo = respNode.TextCase "ErrDesc"genErrDesc = respNode.TextCase elseDim aNode, respTo, respClientID, respMsgID, respErrNo,
respErrDescFor each aNode in respNode.childNodesSelect Case aNode.nodenameCase "To"respTo = aNode.textCase "ClientID"respClientID = aNode.TextCase "MessageID"respMsgID = aNode.TextCase "ErrNo"respErrNo = aNode.TextCase "ErrDesc"respErrDesc = aNode.TextEnd SelectNext' Output the response for testing - Normally this would
update your databaseResponse.Write("<p>A Message")Response.Write("<br>To: " & respTo)Response.Write("<br>Client ID: " &
respClientID)Response.Write("<br>Message ID: " & respMsgID)If(respErrNo <> "") ThenResponse.Write("<br>Error [" & respErrNo
& "] " & respErrDesc)End IfResponse.Write("</p>")End SelectNextIf(genErrNo <> "") ThenResponse.Write("General Error [" & genErrNo & "] "
& genErrDesc)End IfElseResponse.Write("HTTP ErrorStatus Code: " & httpConn.status
& "Response: " & httpConn.responseText)End If%>
<%@ language="VBScript" %> <% Option Explicit'********************************************************************************** ' Sample SMS API XML Interface example in VBScript/ASP ' Copyright Mediaburst 2010 ' ' IMPORTANT NOTE: ' This script is a brief example and should not be used in a live environment ' This example does not include any error checking or error handling, ' error handling must be added before use in a live environment. ' This script is provided without warranty and Mediaburst do not offer ' any support in the use of this example. '**********************************************************************************
' Variable declaration Dim httpConn, responseDoc, serverURL, username, password, originator, content, clientid ' XML variables Dim sendDoc, xmlDecl, msgNode, userNode, passNode, proxyURL
serverURL = "http://sms.message-platform.com/xml/send.aspx"
'********************************************************************************** ' Proxy Server URL - Leave as blank string if not required ' This is only supported if using MSXML version 6 ' e.g. proxyURL = "http://1.2.3.4:3128" proxyURL = ""
' Set your account details here ' API Account Username username = "my_user"
' API Account Password password = "my_pass"
' Message originator (from) originator = "MB_ASP"
' Message Content content = "Hello, this is a test message from my ASP script"
' Client ID / Job ID clientID = "123456"
' This array is just for example purposes, normally you would supply destination addresses Dim destAddrs(1) destAddrs(0) = "441234567890" destAddrs(1) = "449876543210" '**********************************************************************************
' Create an XML Document object - Might have to change this depending upon version of MSXML installed ' This will also need changing at line 96 where it creates MSXML2.ServerXMLHTTP.6.0 ' Version 2.x use Msxml.DOMDocument ' Version 3.0 use Msxml2.DOMDocument.3.0 ' Version 4.0 use Msxml2.DOMDocument.4.0 ' Version 6.0 use Msxml2.DOMDocument.6.0 Set sendDoc = Server.CreateObject("Msxml2.DOMDocument.6.0")
' Create an XML declaration at the top of the document Set xmlDecl = sendDoc.createProcessingInstruction("xml", "version='1.0'") sendDoc.appendChild xmlDecl
Set msgNode = sendDoc.createElement("Message") Set sendDoc.documentElement = msgNode
Set userNode = sendDoc.createElement("Username") Set passNode = sendDoc.createElement("Password")
userNode.nodeTypedValue = username passNode.nodeTypedValue = password msgNode.appendChild userNode msgNode.appendChild passNode
' Loop round the following section for each SMS you want to send Dim anAddr ' single destination address for each anAddr in destAddrs ' Create Nodes Dim smsNode, toNode, contentNode, fromNode, idNode Set smsNode = sendDoc.createElement("SMS") Set toNode = sendDoc.createElement("To") Set contentNode = sendDoc.createElement("Content") Set fromNode = sendDoc.createElement("From") Set idNode = sendDoc.createElement("ClientID") ' Assign values toNode.nodeTypedValue = anAddr contentNode.nodeTypedValue = content fromNode.nodeTypedValue = originator idNode.nodeTypedValue = clientID ' Append nodes to SMS node smsNode.appendChild toNode smsNode.appendChild contentNode smsNode.appendChild fromNode smsNode.appendChild idNode ' Append SMS node to main document msgNode.appendChild smsNode next ' End of loop
' Create HTTP Connection Object Set httpConn = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
' Optionally setup a proxy server If (proxyURL <> "") Then httpConn.setProxy 2, proxyURL End If
' Open synchronous connection httpConn.open "POST", serverURL, false
httpConn.setRequestHeader "Content-type","text/xml" httpConn.Send sendDoc.xml
If(httpConn.status = 200) Then ' Load the response into an XML DOM Document object set responseDoc = httpConn.responseXML Dim respNode, genErrNo, genErrDesc For each respNode in responseDoc.documentElement.childNodes Select Case respNode.nodename Case "ErrNo" genErrNo = respNode.Text Case "ErrDesc" genErrDesc = respNode.Text Case else Dim aNode, respTo, respClientID, respMsgID, respErrNo, respErrDesc For each aNode in respNode.childNodes Select Case aNode.nodename Case "To" respTo = aNode.text Case "ClientID" respClientID = aNode.Text Case "MessageID" respMsgID = aNode.Text Case "ErrNo" respErrNo = aNode.Text Case "ErrDesc" respErrDesc = aNode.Text End Select Next ' Output the response for testing - Normally this would update your database Response.Write("<p>A Message") Response.Write("<br>To: " & respTo) Response.Write("<br>Client ID: " & respClientID) Response.Write("<br>Message ID: " & respMsgID) If(respErrNo <> "") Then Response.Write("<br>Error [" & respErrNo & "] " & respErrDesc) End If Response.Write("</p>") End Select Next If(genErrNo <> "") Then Response.Write("General Error [" & genErrNo & "] " & genErrDesc) End If Else Response.Write("HTTP ErrorStatus Code: " & httpConn.status & "Response: " & httpConn.responseText) End If %>
You might find our Mobile site useful.