|
Advanced Services - SMS Connectivity C# Sample application using HTTP to send a UCS2 or Unicode message |
![]() |
The following sample application written in C# sends a UCS2 or Unicode 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="C#" %>
<html>
<head>
<title>Simple C# example of UCS2 via the HSL HTTP interface</title>
</head>
<body>
<%
// These variables fill out the various parts described in the
// interface specification
String host = "sms.haysystems.com";
String port = "80";
String action = "senducs";
String client_id = "<your client_id>";
String destaddr = "<some fully-qualified MSISDN>";
String ucs2 = "06450631062d0628064b06270020063906270644064500200021";
String secret = "<your secret>";
// Compute the MD5 hash
MD5 md5 = new MD5CryptoServiceProvider();
Encoding encoding = Encoding.ASCII;
String hashInput = secret + ucs2 + destaddr;
byte[] hashInputBytes = encoding.GetBytes(hashInput.ToCharArray());
byte[] rawHash = md5.ComputeHash(hashInputBytes);
// Convert the raw bytes into a string
String hash = "";
for(int i = 0; i < rawHash.GetLength(0); i++) {
String coded = Convert.ToString(rawHash[i], 16);
if(coded.Length == 1) {
coded = "0" + coded;
}
hash += coded;
}
// Build and encode the URL.
String url = "http://" + host + ":" + port + "/" + action + "/?client_id="
+ client_id + "&destaddr="+ destaddr + "&message=" + ucs2 + "&key=" + hash;
// Create an HTTP request
WebRequest httpRequest = WebRequest.Create(url);
WebResponse httpResponse = httpRequest.GetResponse();
Stream stream = httpResponse.GetResponseStream();
StreamReader reader = 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>
ucs2_http_example_csharp.aspx
Copyright © Hay Systems Ltd 2004
Owner: support@haysystems.com 20 September 2004