///Send SMS using C#

//Your APIkey
string apikey = "YourApiKey"; //Approved sender id(6 characters string only).
string senderId = "TESTIN"; //Message channel Promotional=1 or Transactional=2 string channel = "2"; //Default is 0 for normal message, Set 8 for unicode sms string DCS = "0"; //Default is 0 for normal sms, Set 1 for immediate display string flashsms = "0"; //Recipient mobile number (pass with comma seprated if need to send on more then one number).
string number = "9999999"; //Your message to send, Add URL encoding here.
string message = HttpUtility.UrlEncode("Test message"); //Define route.
string route = "default";
//Prepare you post parameters
StringBuilder sbPostData = new StringBuilder();
sbPostData.AppendFormat("authkey={0}", authKey);
sbPostData.AppendFormat("&number={0}", number);
sbPostData.AppendFormat("&message={0}", message);
sbPostData.AppendFormat("&sender={0}", senderId);
sbPostData.AppendFormat("&route={0}", "default");
try
{
//Call Send SMS API
string sendSMSUri = "https://www.smsgatewayhub.com/api/mt/SendSMS?"; //Create HTTPWebrequest
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(sendSMSUri); //Prepare and Add URL Encoded data
UTF8Encoding encoding = new UTF8Encoding();
byte[] data = encoding.GetBytes(sbPostData.ToString()); //Specify post method
httpWReq.Method = "POST";
httpWReq.ContentType = "application/x-www-form-urlencoded";
httpWReq.ContentLength = data.Length; using (Stream stream = httpWReq.GetRequestStream())
{
stream.Write(data, 0, data.Length);
} //Get the response
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string responseString = reader.ReadToEnd();
//Close the response
reader.Close();
response.Close();
}
catch (SystemException ex)
{
MessageBox.Show(ex.Message.ToString());
}