HTTP Reply Service

white

Introduction to HTTP Reply Service

The “Red Oxygen HTTP Reply Service User Guide” provides sample ASP code for a simple interface for programmers to receive SMS reply to their Web Server in XML or HTML form format.

Client web servers

The client web server requires an ASP page or equivalent to receive and process the reply.

Note: The example code in this document is written for ASP.

Properties

Parameter Type Description Example
CustomerId Number This is your Account ID without “CI000”. If your Account ID is “CI00012345”. Then this parameter is “12345” 12345
EmailId Char(24) Numreic 81001201120271
SmsId Char(24) Numreic 19232595
UserEmail Char(64) String – system user’s email address support@redoxygen.com
UserName Char(256) String – system user’s name RedOxygen Support
DestTN CHAR (24) String – replying user’s phone number 61409000000
DestName CHAR (256) String – replying user’s name John
ReplyURL CHAR (512) String – URL you provide to Red Oxygen to call when replies are received http://www.customerdomain.com/SMSReplies.asp
ReplyText CHAR (4000) String – reply text This is my test reply message

Response from the client web server

Successful response

If the Client Server received the http request and successfully processed data, the reply response result will be “000” packaged as follows:

<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 3.2 Final//EN"">
<HTML>
  <BODY>
    <RESULT>000</RESULT>
  </BODY>
</HTML>

Unsuccessful response

If the client server did not receive the http request successfully because of an error the reply response result will be a three digit error number and be packaged as follows:

<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 3.2 Final//EN"">
   <HTML>
      <BODY>
         <RESULT>100</RESULT>
      </BODY>
</HTML>

Note: In this example error “100” could be taken to indicate that no data block post was received.

Methods (HTTP XML and HTML)

HTTP XML

This Red Oxygen HTTP Reply Service method will format the sms reply in the following XML format and uses Http Post to send the request to the Web Server. The XML values are URL encoded.

Example

<?xml version="1.0" encoding="UTF-8"?>
<DATA>
<CustomerId>12345</CustomerId>
<EmailId>81001201120271</EmailId>
<SmsId>19232595</SmsId>
<UserEmail>support@redoxygen.com</UserEmail>
<UserName>RedOxygen+Support</UserName>
<DestTN>61409000000</DestTN >
<DestName>John</DestName>
<ReplyURL>http://www.customerdomain.com/SMSReplies.asp</ReplyURL>
<ReplyText>This+is+my+test+reply+message</ReplyText>
</DATA>

Sample Client Web Server (ASP) Code for XML

<%@ Language=VBScript %>
<%
  szPageTitle = "TestHttpReply"
 
  szPageUser = Request.QueryString("PageUser")
  szPagePass = Request.QueryString("PagePass")
  if szPageUser = "MyUser" and szPagePass = "MyPass" then
    szErrorCode = "000"
  else
    szErrorCode = "-10"
  end if
 
  szTestString = Request.QueryString("TestString")
  szRespText = Replace(Request.Form, "'", "''")
 
  if szRespText = "" then
    if szTestString = "Yes" then
      '/* This code segment is provided for testing purposes, it emulates */
      '/* the Red Oxygen calling this page by use of recursion, (i.e. it */
      '/* calls itself, with a valid reply data. */
      '/* To call this segment, you need to add the "&TestString=Yes" */
      '/* to the URL. */
      '/* In this format, this code would never be called by if the reply */
      '/* is instigated by the Red Oxygen server because the szRespText */
      '/* would never be "", and is safe to leave here. */
      szRespText = "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCRLF _
                 & "<DATA>" & vbCRLF _
                 & " <CustomerId>12345</CustomerId>" & vbCRLF _
                 & " <EmailId>81001201120271</EmailId>" & vbCRLF _
                 & " <SmsId>19232595</SmsId>" & vbCRLF _
                 & " <UserEmail>support@redoxygen.com</UserEmail>" & vbCRLF _
                 & " <UserName>RedOxygen+Support</UserName>" & vbCRLF _
                 & " <DestTN>61409000000</DestTN >" & vbCRLF _
                 & " <DestName>John</DestName>" & vbCRLF _
                 & " <ReplyURL>http://www.customerdomain.com/SMSReplies.asp</ReplyURL>" & vbCRLF _
                 & " <ReplyText>This+is+my+test+reply</ReplyText>" & vbCRLF _
                 & "</DATA>" & vbCRLF
                 '/*  This code segment assigns  the address to the szURL variable for the server to call itself*/                                          
                 ‘/*  for the HTTP query string*/
      szURL = "Http://" & Request.servervariables("SERVER_NAME") & Request.servervariables("PATH_INFO") & "?" & Request.QueryString
 
      set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
      objHttp.open "POST", szURL, false
      objHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
      objHttp.Send szRespText
 
      if (objHttp.status <> 200 ) then
        szErrorCode = "200"
        szSkipToEnd = "No"
      else
        szResponse = objHttp.responseText
        szResult = Replace(szResponse, "<BODY>", "<BODY>Recursive call using test data<BR>")
        Response.write(szResult)
        szSkipToEnd = "Yes"
      end if
      set objHttp = nothing
    else
      szErrorCode = "100"
    end if
  end if
 
  if szSkipToEnd <> "Yes" then
    '/* This is the pain body of the program. First we log onto an Oracle Database. */
  szSkipDB = Request.QueryString("SkipDB")
 
  if szSkipDB = "" then
    szDatabase = "MY_ORA_DB"
    szDBUser = "scott"
    szDBPass = "tiger"
 
    Set DBConn = Server.CreateObject("ADODB.Connection")
    DBConn.ConnectionTimeout = 15
    DBConn.CommandTimeout = 15
    DBConn.CursorLocation = 3
    DBConn.Open "Provider=MSDAORA.1; Data Source=" & szDatabase & "; User Id=" &_
                szDBUser & "; Password=" & szDBPass & "; " &_
                "Persist Security Info=True; Max Pool Size=20; Min Pool Size=1", _
                szDBUser, szDBPass
    if DBConn.Errors.Count > 0 then
      szErrorCode = "-99"
    end if
  end if
 
  if InStr(szRespText, "<") > 0 then
    '/* Here we split the XML up into Key - Value pairs, nd assign them to variables. */
    aReplyTmp = split(szRespText, "<")
    i = 0
    do while left(aReplyTmp(i), 6) <> "/DATA>"
      if InStr(aReplyTmp(i), ">") > 0 then
        aSplitTemp = split(aReplyTmp(i), ">")
        if aSplitTemp(0) = "CustomerId" then
          szCustomerId = aSplitTemp(1)
        elseif aSplitTemp(0) = "EmailId" then
          szEmailId = aSplitTemp(1)
        elseif aSplitTemp(0) = "SmsId" then
          szSmsId = aSplitTemp(1)
        elseif aSplitTemp(0) = "UserEmail" then
          szUserEmail = aSplitTemp(1)
        elseif aSplitTemp(0) = "UserName" then
          szUserName = aSplitTemp(1)
        elseif aSplitTemp(0) = "DestTN" then
          szDestTN = aSplitTemp(1)
        elseif aSplitTemp(0) = "DestName" then
          szDestName = aSplitTemp(1)
        elseif aSplitTemp(0) = "ReplyURL" then 
          szReplyURL = aSplitTemp(1)
        elseif aSplitTemp(0) = "ReplyText" then
          szReplyText = aSplitTemp(1)
        end if
      end if
      i = i + 1
    loop
  end if
 
  '/* And then insert the data into a table, for later processing... */
  sql="INSERT INTO http_reply ( CustomerId, EmailId, SmsId, UserEmail, UserName, " & vbCRLF _
    & " DestTN, DestName, ReplyURL, ReplyText, ErrorCode ) " & vbCRLF _
    & "VALUES ('" & szCustomerId & "', '" & szEmailId & "', '" & szSmsId & "', " & vbCRLF _
    & " '" & szUserEmail & "', '" & szUserName & "', '" & szDestTN & "', " & vbCRLF _
    & " '" & szDestName & "', '" & szReplyURL & "', '"& szReplyText & "', '" & szErrorCode & "')"
    if szSkipDB = "Yes" then
      '/* For debug purposes we return the SQL from the above database insert statement */
      szResult = "Http://" & Request.servervariables("SERVER_NAME") & _
                 Request.servervariables("PATH_INFO") & "<BR><PRE>" & _
                 szRespText & vbCRLF & sql & "</PRE>"
    else
      Set Newsrst = DBconn.Execute (sql)
      szResult = "<RESULT>" & szErrorCode & "</RESULT>"
    end if
 
  '/* And Finally return the result. */
    Response.write("<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 3.2 Final//EN"">" & vbCRLF)
    Response.write("<TITLE>" & szPageTitle & "</TITLE>" & vbCRLF)
    Response.write("<HTML>" & vbCRLF)
    Response.write("<BODY>" & vbCRLF)
    Response.write(szResult & vbCRLF)
    Response.write("</BODY>" & vbCRLF)
    Response.write("</HTML>" & vbCRLF)
  end if
%>

HTTP HTML Form

This Red Oxygen HTTP Reply Service method will format the sms reply in the following HTML form format and uses Http Post to send the request to the Web Servers.

Example:
&CustomerId=123456
&EmailId=81001201120271
&SmsId=19232595
&UserEmail=support@redoxygen.com
&UserName=Test+User
&DestTN=61412345678
&DestName=John+Smith
&ReplyURL=http://www.customerdomain.com/SMSReplies.asp
&ReplyText=This+is+my+test+reply+message
Sample Client Web Server (ASP) Code for HTML form
<%@ Language=VBScript %>
<% 
  szPageUser   = Request.QueryString("PageUser")
  szPagePass   = Request.QueryString("PagePass")
  if szPageUser = "MyUser" and szPagePass = "MyPass" then
    szErrorCode  = "000"
  else
    szErrorCode  = "-10"
  end if
 
  szTestString = Request.QueryString("TestString")
  szRespText   = Replace(Request.Form, "'", "''")
 
'/*  This code segment assigns the address to the szURL variable for the server to call itself*/                                     
'/*  for the HTTP query string*/
 szURL = "Http://" & Request.servervariables("SERVER_NAME") & _
              Request.servervariables("PATH_INFO") & "?" & Request.QueryString
 
  if szRespText = "" then
    if szTestString = "Yes" then
       szPageTitle  = "TestHttpForm"
 
      '/*  This code segment is provided for testing purposes, it emulates */
      '/*  the Red Oxygen calling this page by use of recursion, (i.e. it  */
      '/*  calls itself, with a valid reply data.                          */
      '/*  To call this segment, you need to add the "&TestString=Yes"   */
      '/*  to the URL.                                                     */
      '/*  In this format, this code would never be called by if the reply */
      '/*  is instigated by the   Red Oxygen server because the szRespText */
      '/*  would never be "", and is safe to leave here.                   */
      Response.write("<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 3.2 Final//EN"">" & vbCRLF)
      Response.write("<TITLE>" & szPageTitle & "</TITLE>" & vbCRLF)
      Response.write("<HTML>" & vbCRLF)
      Response.write("<BODY>" & vbCRLF)
      Response.write("<FORM name=request action=" & szURL& " method=post>" & vbCRLF)
      Response.write("  <TABLE>" & vbCRLF)
      Response.write("    <TR>" & vbCRLF)
      Response.write("      <TD>Customer Id:</TD>" & vbCRLF)
      Response.write("      <TD><INPUT type=text name=CustomerId value=1></TD>" & vbCRLF)
      Response.write("    </TR><TR>" & vbCRLF)
      Response.write("      <TD>Email Id:</TD>" & vbCRLF)
      Response.write("      <TD><INPUT type=text name=EmailId value=81001201120271></TD>" & vbCRLF )
      Response.write("    </TR><TR>" & vbCRLF)
      Response.write("      <TD>SMS Id:</TD>" & vbCRLF)
      Response.write("      <TD> <INPUT type=text name=SmsId value=19232595></TD>" & vbCRLF)
      Response.write("    </TR><TR>" & vbCRLF)
      Response.write("      <TD>User email:</TD>" & vbCRLF)
      Response.write("      <TD><INPUT type=text name=UserEmail value=test@redoxygen.com ></TD>" & vbCRLF)
      Response.write("    </TR><TR>" & vbCRLF)
      Response.write("      <TD>User name:</TD>" & vbCRLF)
      Response.write("      <TD><INPUT type=text name=UserName value=Test+User></TD>" & vbCRLF)
      Response.write("    </TR><TR>" & vbCRLF)
      Response.write("      <TD>Destination:</TD>" & vbCRLF)
      Response.write("      <TD><INPUT type=text name=DestTN value=61417156776></TD>" & vbCRLF)
      Response.write("    </TR><TR>" & vbCRLF)
      Response.write("      <TD>Destination name:</TD>" & vbCRLF)
      Response.write("      <TD><INPUT type=text name=DestName value=John+Smith></TD>" & vbCRLF)
      Response.write("    </TR><TR>" & vbCRLF)
      Response.write("      <TD>Reply URL:</TD>" & vbCRLF)
      Response.write("      <TD><INPUT type=text name=ReplyURL value=http://www.customerdomain.com/SMSReplies.asp ></TD>" & vbCRLF)
      Response.write("    </TR><TR>" & vbCRLF)
      Response.write("      <TD>Reply text:</TD>" & vbCRLF)
      Response.write("      <TD><INPUT type=text name=ReplyText value=This+is+my+test+reply+message></TD>" & vbCRLF)
      Response.write("    </TR><TR>" & vbCRLF)
      Response.write("      <TD colspan=2><INPUT type=submit value=submit></TD>" & vbCRLF)
      Response.write("    </TR>" & vbCRLF)
      Response.write("  </TABLE>" & vbCRLF)
      Response.write("</FORM>" & vbCRLF)
      Response.write("</BODY>" & vbCRLF)
      Response.write("</HTML>" & vbCRLF)
  end if
end if
 
    szSkipDB     = Request.QueryString("SkipDB")
 
    if szSkipDB = "" then
      szDatabase   = "MY_ORA_DB"
      szDBUser     = "scott"
      szDBPass     = "tiger"
 
      Set DBConn = Server.CreateObject("ADODB.Connection")
      DBConn.ConnectionTimeout = 15
      DBConn.CommandTimeout = 15
      DBConn.CursorLocation = 3
      DBConn.Open "Provider=MSDAORA.1; Data Source=" & szDatabase & "; User Id=" &_
                  szDBUser & "; Password=" & szDBPass & "; " &_
                  "Persist Security Info=True; Max Pool Size=20; Min Pool Size=1", _
                  szDBUser, szDBPass
      if DBConn.Errors.Count > 0 then
        szErrorCode = "-99"
      end if
    end if
 
 if szRespText <>  "" then
    szPageTitle  = "TestHttpReply"
      '/*  This section of code assigns the posted form field information to variables for insertion into the database. */
   szCustomerId = Request.Form("CustomerId")  
   szEmailId    = Request.Form("EmailId")
   szSmsId      = Request.Form("SmsId")
   szUserEmail  = Request.Form("UserEmail")
   szUserName   = Request.Form("UserName")
   szDestTN     = Request.Form("DestTN")
   szDestName   = Request.Form("DestName")
   szReplyURL   = Request.Form("ReplyURL")
   szReplyText  = Request.Form("ReplyText")
 
    '/*  And then insert the data into a table, for later processing...  */
    sql="INSERT INTO http_reply ( CustomerId, EmailId, SmsId, UserEmail, UserName, " & vbCRLF _
      & "                         DestTN, DestName, ReplyURL, ReplyText, ErrorCode ) " & vbCRLF _
      & "VALUES ('" & szCustomerId & "', '" & szEmailId & "', '" & szSmsId  & "', " & vbCRLF _
      & "        '" & szUserEmail & "', '" & szUserName & "', '" & szDestTN  & "', " & vbCRLF _
      & "        '" & szDestName & "', '" & szReplyURL & "', '" & szReplyText & "', '" & szErrorCode  & "')"
 
    if szSkipDB = "Yes" then
      '/*  For debug purposes we return the SQL from the above database insert statement          */
      szResult = "Http://" & Request.servervariables("SERVER_NAME") & _
                 Request.servervariables("PATH_INFO") & "<BR><PRE>" & _
                 szRespText & vbCRLF & sql & "</PRE>"
    else
      Set Newsrst = DBconn.Execute (sql)
      szResult = "<RESULT>" & szErrorCode & "</RESULT>"
    end if
 
    '/*  And Finally return the result.                                                         */
    Response.write("<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 3.2 Final//EN"">" & vbCRLF)
    Response.write("<TITLE>" & szPageTitle & "</TITLE>" & vbCRLF)
    Response.write("<HTML>" & vbCRLF)
    Response.write("<BODY>" & vbCRLF)
    Response.write(szResult & vbCRLF)
    Response.write("</BODY>" & vbCRLF)
    Response.write("</HTML>" & vbCRLF)
  end if
%>

Testing URL for code samples

The sample codes can be called with the following URL:

http://localhost//TestHttpReply.asp?PageUser=MyUser&PagePass=MyPass&TestString=Yes&SkipDB=Yes

TestString=Yes” and “SkipDB=Yes” are parameters passed for testing purposes only.

Want us to set it up for you?

Get in touch with our team and we will get back to you as soon as possible!

    white