Developer Tools
BasicText SMSCampaignSendOTPVirtual NumberResellerSample CodePhonebookError Code
HOME LOGIN SIGN UP
  • Send SMS in PHP
  • Send SMS in Python
  • Send SMS in JAVA
  • Send SMS in JAVA For XML API
  • Send SMS in C#
  • Send SMS in Google Appscript
  • Send SMS in Windows 8
  • Send SMS in Android
  • Send SMS in iOS
  • Send SMS in VB6
  • Send SMS in Oracle
  • Send SMS in Go Language
  • Api Postman Collection

HTTP Send SMS API using C#

Code:

//Your authentication key
string authKey = "YourAuthKey"; //Multiple mobiles numbers separated by comma
string mobileNumber = "9999999"; //Sender ID,While using route4 sender id should be 6 characters long.
string senderId = "102234"; //Your message to send, Add URL encoding here.
string message = HttpUtility.UrlEncode("Test message");
//Prepare you post parameters
StringBuilder sbPostData = new StringBuilder();
sbPostData.AppendFormat("authkey={0}", authKey);
sbPostData.AppendFormat("&mobiles={0}", mobileNumber);
sbPostData.AppendFormat("&message={0}", message);
sbPostData.AppendFormat("&sender={0}", senderId);
sbPostData.AppendFormat("&route={0}", "default");
try
{
//Call Send SMS API
string sendSMSUri = "http://api.msg91.com/api/sendhttp.php"; //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());
}

© 2008-2025 | All Rights Reserved.