C# code sample (Unicode)
Simplest case - sending a single Unicode message:
using System.Net;
using System;
using System.Web;
using System.Text;
using System.IO;
namespace SMS{
public class SendSMS{
static string stringToHex(string s){
string hex = "";
foreach (char c in s)
{
int tmp = c;
hex += String.Format("{0:x4}", (uint)System.Convert.ToUInt32(tmp.ToString()));
}
return hex;
}
public static string Post(string url, string data) {
string result = null;
try
{
byte[] buffer = Encoding.Default.GetBytes(data);
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
WebReq.Method = "POST";
WebReq.ContentType = "application/x-www-form-urlencoded";
WebReq.ContentLength = buffer.Length;
Stream PostData = WebReq.GetRequestStream();
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Console.WriteLine(WebResp.StatusCode);
Stream Response = WebResp.GetResponseStream();
StreamReader _Response = new StreamReader(Response);
result = _Response.ReadToEnd();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return result.Trim()+"\n";
}
static void Main( ){
string url = "http://bulksms.2way.co.za:5567/eapi/submission/send_sms/2/2.0";
/*****************************************************************************************************
**Construct data
*****************************************************************************************************/
/*
* Note the suggested encoding for the some parameters, notably
* the username, password and especially the message. ISO-8859-1
* is essentially the character set that we use for message bodies,
* with a few exceptions for e.g. Greek characters. For a full list,
* see: http://bulksms.vsms.net/docs/eapi/submission/character_encoding/
*/
//
string data = "";
data += "username=" + HttpUtility.UrlEncode("your_username", System.Text.Encoding.GetEncoding("ISO-8859-1"));
data += "&password=" + HttpUtility.UrlEncode("your_password", System.Text.Encoding.GetEncoding("ISO-8859-1"));
data += "&message=" + stringToHex("This is a test: ¥ € ₣");
data += "&dca=16bit";
data += "&want_report=1";
data += "&msisdn=27712345678";
string sms_result = Post(url, data);
string[] parts = sms_result.Split('|');
string statusCode = parts[0];
string statusString = parts[1];
if ( !statusCode.Equals("0") ) {
Console.WriteLine( "Error: " + statusCode + ": " + statusString );
}
else {
Console.WriteLine( "Success: batch ID " + parts[2] );
}
}
}
}