Message Send In C#

  1. string authKey = authkey;  
  2. //Multiple mobiles numbers separated by comma  
  3. string mobileNumber = txtphno.Text;  
  4. //Sender ID,While using route4 sender id should be 6 characters long.  
  5. string senderId = username1;  
  6. //Your message to send, Add URL encoding here.  
  7. string msg = HttpUtility.UrlEncode(txtmessage.Text);  
  8. //Prepare you post parameters  
  9. StringBuilder sbPostData = new StringBuilder();  
  10. sbPostData.AppendFormat("authkey={0}", authKey);  
  11. sbPostData.AppendFormat("&mobiles={0}", mobileNumber);  
  12. sbPostData.AppendFormat("&message={0}", msg);  
  13. sbPostData.AppendFormat("&sender={0}", senderId);  
  14. sbPostData.AppendFormat("&route={0}""4");  
  15. try {  
  16.     //Call Send SMS API  
  17.     string sendSMSUri = "Your key";  
  18.     //Create HTTPWebrequest  
  19.     HttpWebRequest httpWReq = (HttpWebRequest) WebRequest.Create(sendSMSUri);  
  20.     //Prepare and Add URL Encoded data  
  21.     UTF8Encoding encoding = new UTF8Encoding();  
  22.     byte[] data = encoding.GetBytes(sbPostData.ToString());  
  23.     //Specify post method  
  24.     httpWReq.Method = "POST";  
  25.     httpWReq.ContentType = "application/x-www-form-urlencoded";  
  26.     httpWReq.ContentLength = data.Length;  
  27.     using(Stream stream = httpWReq.GetRequestStream()) {  
  28.             stream.Write(data, 0, data.Length);  
  29.         }  
  30.         //Get the response  
  31.     HttpWebResponse response = (HttpWebResponse) httpWReq.GetResponse();  
  32.     StreamReader reader = new StreamReader(response.GetResponseStream());  
  33.     string responseString = reader.ReadToEnd();  
  34.     //Close the response  
  35.     reader.Close();  
  36.     response.Close();  
  37.     MessageBox.Show("Your Message has been Sent.""Message"