Sample Code
In order to assist you in integrating with our Web Service API's as rapidly as possible,
we offer the following free source code, scripts and applications in a number of common programming
languages. The code is provided as-is, without warranty of any kind, either expressed or implied, and we
strongly urge all developers to exhaustively test their applications based on this code prior to deployment.
We gratefully acknowledge that several of these samples
have been provided by our customers. Further contributions will be
gratefully received and acknowledged and should be sent via a website
support request.
The following sites may also be of interest to developers. Connection Software is not
responsible for the content of external internet sites.
Language Support: Visual C++, Visual Basic 6, Visual Basic 7.NET
API: SMS Web Service SOAP API
Description: A Windows DLL based SDK that allows you to simply add the ability to send SMS (and optionally receive)
from any application, programming language or scripting language that can call a DLL. Supports secure connections and is compatible with
many corporate firewalls and proxy servers. It includes sample code for Visual C++, Visual Basic 6 and Visual Basic 7.NET.
Contributed By: Connection Software
More info and download...
Language Support: C++
API: SMS Web Service SOAP API
Description: A linux based solution for sending SMS using the SOAP to SMS API. The makefile downloads the WSDL file from the
csoft.co.uk website and then uses gSOAP to generate the client code to make the SOAP calls. An included main.cpp stub provides a
simple command-line based method for intitiating the sending of a plain text or flash message.
Contributed By: Connection Software
Download (ZIP file)
Language Support: J2SE (Java)
API: SMS Web Service HTTP API
Description: A complete dialog-based sample application written using J2SE and the Netbeans 4.0 IDE which
prompts for your Username, PIN, To: number list, and Message and submits it when you press Send. The return from the
server is displayed in a pop-up message box.
Contributed By: Connection Software
Download (ZIP file)
Language Support: Microsoft Visual C++ .NET 2003
API: SMS Web Service SOAP API
Description: A complete dialog-based sample application written using VC++ .NET 2003 which
prompts for your Username, PIN, To: number list, and Message and submits it when you press Send. The return from the
server is displayed in a pop-up message box.
Contributed By: Connection Software
Download (ZIP File)
Language Support: Microsoft Visual C# .NET
API: SMS Web Service SOAP API
Description: A complete dialog-based sample application written using C#.NET which
prompts for your Username, PIN, To: number list, and Message and submits it when you press Send. The return from the
server is displayed in a pop-up message box.
Contributed By: Colin Millar
Download (ZIP file)
Language Support: Microsoft C#
API: SMS Web Service HTTP API
Description: Send SMS messages using the SMS Web Service HTTP API
Contributed By: Jon Gianni of J D Wetherspoon plc
Download Now (ZIP File)
Language Support: Microsoft VB.NET
API: SMS Web Service HTTP API (Format 1)
Description: Sends SMS text messages with fail-over. Attempts to send the message using the primary server and checks the server response. If there is a problem, it tries the
secondary server. If either server responds with success ("01") it exits the loop.
Contributed: Mario Menti
<WebMethod()> _
Public Function SendSMS(ByVal msg As String, ByVal sendTo As String)
Dim useMsg As String
Dim i As Integer
Dim c As String
' Convert characters in the message text
useMsg = ""
For i = 1 To Len(msg)
c = Mid(msg, i, 1)
Select Case c
Case vbCrLf : c = "%0A"
Case vbLf : c = "%0D"
Case " " : c = "%20"
Case "+" : c = "%2B"
Case """" : c = "%22"
Case "#" : c = "%23"
Case "%" : c = "%25"
Case "&" : c = "%26"
Case "," : c = "%2C"
Case "." : c = "%2E"
Case "/" : c = "%2F"
Case ":" : c = "%3A"
Case ";" : c = "%3B"
Case "<" : c = "%3C"
Case "=" : c = "%3D"
Case ">" : c = "%3E"
Case "?" : c = "%3F"
Case "¡" : c = "%A1"
Case "£" : c = "%A3"
Case "#" : c = "%A4"
Case "¥" : c = "%A5"
Case "§" : c = "%A7"
Case "Ä" : c = "%C4"
Case "Å" : c = "%C5"
Case "à" : c = "%E0"
Case "ä" : c = "%E4"
Case "å" : c = "%E5"
Case "Æ" : c = "%C6"
Case "Ç" : c = "%C7"
Case "É" : c = "%C9"
Case "è" : c = "%E8"
Case "é" : c = "%E9"
Case "ì" : c = "%EC"
Case "Ñ" : c = "%D1"
Case "ñ" : c = "%F1"
Case "ò" : c = "%F2"
Case "ö" : c = "%F6"
Case "Ø" : c = "%D8"
Case "Ö" : c = "%D6"
Case "Ü" : c = "%DC"
Case "ù" : c = "%F9"
Case "ü" : c = "%FC"
Case "ß" : c = "%DF"
End Select
useMsg = useMsg + c
Next
Dim Query As String
Dim qLen As Integer
' Construct the HTTP query string
Query = "UN=username.12345" _
& "&PIN=12345678" _
& "&N=" & sendTo _
& "&M=" & useMsg
qLen = Len(Query)
' Request and Response objects
Dim objReq As System.Net.HttpWebRequest
Dim objRes As System.Net.HttpWebResponse
Dim sr As System.IO.StreamReader
Dim sw As System.IO.StreamWriter
Dim Gateways(1)
Dim gw
Gateways(0) = "www.csoft.co.uk/sendsms"
Gateways(1) = "www2.csoft.co.uk/sendsms"
For Each gw In Gateways
objReq = System.Net.WebRequest.Create("http://" & CStr(gw))
objReq.Method = "POST"
objReq.ContentType = "application/x-www-form-urlencoded; charset=""utf-8"""
objReq.ContentLength = qLen
sw = New System.IO.StreamWriter(objReq.GetRequestStream())
sw.Write(Query)
sw.Close()
' get server response
objRes = objReq.GetResponse
sr = New System.IO.StreamReader(objRes.GetResponseStream())
If CStr(Left(sr.ReadToEnd, 2)) = "01" Then ' success, exit loop
sr.Close()
objRes.Close()
Exit For
End If
Next
End Function
Language Support: Microsoft Visual Basic ASP Script
API: SMS Web Service HTTP API
Description: Sends SMS text messages using the SMS Web Service HTTP API
Contributed By: Mark Tynan
Download Now (ZIP File)
Language Support: Microsoft Visual Basic
API: SMS Web Service Email Format 1 API
Description: Sends SMS text messages using the email format 1 API
Contributed By: Barry Stanton
<%
Response.Expires = 0
Dim message_body message_body = "Identifier=1234567"&
vbCrLf &"|447700912345|Hello World|"& vbCrlf
Set ObjMail = Server.CreateObject("CDONTS.NewMail")
objMail.To = "ANother.12345@itsarrived.net"
objMail.Subject ="format1"
objMail.From = "user@somecompany.co.uk"
objMail.Body = message_body ObjMail.Send
Set ObjMail = Nothing Response.Write"sent"
%>
Language Support: Microsoft Visual BASIC
API: MMS Web Services SOAP & HTTP API's
Description: Hex encodes a binary file such that it can then be submitted using one of the API's that needs any binary data hex encoded first.
Contributed By: Kenric Mckenzie
Function HexConvert(ByVal strFileName As String) As String
Dim s As String
Dim hx As String
Open strFileName For Binary Access Read As 1
hx = ""
While (Not EOF(1))
c = Input$(1, 1)
If (c <> "") Then
s = Hex(Asc(c))
If (Len(s) = 1) Then
hx = hx + "0" + s
Else
hx = hx + s
End If
End if
Wend
HexConvert = hx
End Function
Language Support: Perl
API: SMS Web Service HTTP API
Description: Perl script to send SMS messages using the SMS Web Service HTTP API. The Perl modules
Crypt::SSLeay, LWP::UserAgent and HTTP must be installed.
Contributed By: Dean Browett (pushnow.com)
use LWP::UserAgent;
sub sendViaSecureHttp {
my ($contentLength, $queryData) = @_;
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(POST => 'https://www.csoft.co.uk/sendsms');
$req->content_type('application/x-www-form-urlencoded;charset=\"utf-8\"');
$req->content_length($contentLength);
$req->content($queryData);
my $res = $ua->request($req);
if ($res->is_success) {
#could send email here
print $res->as_string;
return 1;
}
print "Failed: ", $res->status_line, "\n";
return 0;
}
Language Support: Perl
API: SMS Web Service HTTP API
Description: Sends SMS text messages. Perl modules LWP::UserAgent and HTTP::Request::Common must be installed.
Contributed By: Unknown
#!/usr/bin/perl
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
my $url_sendsms = "http://www.csoft.co.uk/sendsms";
my($ua,$request,$response,%field);
undef %field;
$field{Username} = "ANOther.61234";
$field{PIN} = "123456";
$field{Message} = "This is a test message";
$field{SendTo} = "447700900010";
$ua = LWP::UserAgent->new;
$request = POST $url_sendsms,\%field;
$response = $ua->request($request);
if($response->is_success) {
print $response->as_string;
}
else {
print "Failed: ", $response->status_line, "\n";
}
Language Support: Perl
API: MMS Web Services SOAP & HTTP API's
Description: Hex encodes a binary file (image.jpg) such that it can then be submitted using one of the API's that needs any binary data hex encoded first.
Contributed By: Kenric Mckenzie
open(F, "image.jpg") || die $!;
$s = $hx = "";
while (read(F, $s, 1) > 0) {
$hx .= sprintf("%02X", ord($s));
}
close F;
print "The hex-encoded GIF file is: $hx\n";
Language Support: Perl
API: SMS Web Services HTTP API
Description: Receives an HTTP POST from the messaging server and parses out the MO SMS data.
Contributed By: Connection Software
Download Script (ZIP)
Language Support: PHP
API: SMS/MMS Web Services HTTP API's
Description: Sends SMS text messages including all the encoding issues.
Contributed By: Simon Moore
Download Script
Language Support: Unix Shell
API: MMS Web Services SOAP & HTTP API's
Description: Hex encodes a binaey file (image.jpg) such that it can then be submitted using one of the API's that needs any binary data hex encoded first.
Contributed By: Kenric Mckenzie
od -v -t x1 image.jpg | \
sed -e 's/^........//' | \
tr 'a-f' 'A-F' | \
tr -dc '0-9A-F'
Language Support: Command Line
API: Sending SMS Text Messages Web Service HTTP API
Description: Sends secure text messages using the free, open source, multi-platform command line cURL software
Contributed By: Connection Software
Sends a plain text message.
curl -v -H "Content-Type: application/x-www-form-urlencoded" --user-agent "ConnectionSoftware/TestScript"
--data "Username=ANOther.12345&PIN=1234567&SendTo=447700912345,447700911223&Message=Hello%20World&ResponseFormat=3"
https://www.csoft.co.uk/sendsms
Sends a plain text message to a particular port (useful for J2ME MIDlets).
curl -v -H "Content-Type: application/x-www-form-urlencoded" --user-agent "CSoft Test/Script" --data
"Username=ANOther.12345&PIN=12345678&SendTo=447700912345&ResponseFormat=4&SmsSubmitPduDataCodingScheme=00
&SmsSubmitPduProtocolIdentifier=00&SmsSubmitPduUserDataHeader=
06050450000000&Message=This%20is%20a%20message%20to%20port%205000"
https://www.csoft.co.uk/sendsms
Download Now (ZIP File)
Language Support: Java
API: SMS Web Service HTTP API
Description: Java class code to send an SMS using the SMS Web Service HTTP API. Uses jakarta
commons httpclient for the http work to deliver sms (simple, flash and wappush) and query account status.
Contributed By: Philip Gleghorn
Download Now (ZIP File)
Language Support: HTML
API: SMS Web Service HTTP API
Description: HTML Form to send an SMS message using the SMS Web Service HTTP API
Contributed By: Connection Software
Download Script (ZIP File)
Language Support: HTML
API: SMS Web Service HTTP API
Description: HTML Form to send an MMS message using the MMS Web Service HTTP API. Note that the file
data must be a hex encoded string that is pasted into the form, not a file path or the binary file data.
Contributed By: Connection Software
Download Script (ZIP File)
|