|
Advanced Services - SMS Connectivity VB for ASP.NET Sample application using HTTP to send an EMS message |
![]() |
The following sample application written in VB for ASP.NET sends an EMS message to a single mobile telephone. The application uses HTTP to communicate with HSL's systems. To send to more than one mobile telephone at a time, separate each mobile number in the destaddr field by a comma (e.g. "447968000111,447720000111,3378100100").
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Security.Cryptography" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<%@ Page Language="VB" %>
<html>
<head>
<title>Simple VBScript (ASP.NET) example EMS via the HSL HTTP interface</title>
</head>
<body>
<%
' These variables fill out the various parts described in the
' interface specification
Const host = "sms.haysystems.com"
Const port = "80"
Const action = "submitsm"
Const client_id = "<your client_id>"
Const destaddr = "<some fully-qualified MSISDN>"
Dim shortmessage
shortmessage = "7C0C7A00424547494E3A494D454C4F44590D0A56455253494F4E3A312E320" _
& "D0A464F524D41543A434C415353312E300D0A4D454C4F44593A6433236333" _
& "6433236333643372326433236333643365332366336533236633673361332" _
& "36733613323673361337232613323673361330D0A454E443A494D454C4F44" _
& "590D0A"
Const secret = "<your secret>"
' Compute the MD5 hash
Dim md5 As New MD5CryptoServiceProvider()
Dim encoding As Encoding = Encoding.ASCII
Dim hashInput = secret & shortmessage & destaddr
Dim hashInputBytes As Byte() = encoding.GetBytes(hashInput.ToCharArray())
Dim rawHash() As Byte = md5.ComputeHash(hashInputBytes)
' Convert the raw bytes into a string
Dim hash = ""
Dim i As Integer
For i = 0 To rawHash.GetLength(0) - 1
Dim coded As String = Convert.ToString(rawHash(i), 16)
If coded.Length = 1 Then
coded = "0" & coded
End If
hash = hash & coded
Next
' Build and encode the URL.
Dim url = "http://" & host & ":" & port & "/" & action & "/?client_id=" _
& client_id & "&destaddr=" & destaddr & "&esm=64&shortmessage=" _
& shortmessage & "&key=" & hash
'Create an HTTP request
Dim httpRequest As WebRequest = WebRequest.Create(url)
Dim httpResponse As WebResponse = httpRequest.GetResponse()
Dim stream As Stream = httpResponse.GetResponseStream()
Dim reader As New StreamReader(stream)
' Make the request and print the result
Response.Write("<p>Submission result: ")
Response.Write(reader.ReadToEnd())
Response.Write("</p>")
reader.Close()
%>
</body>
</html>
ems_http_example_vb.aspx
Copyright © Hay Systems Ltd 2004
Owner: support@haysystems.com 20 September 2004