Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
private void send_sms_direct(string numbers, string sms)
    {
        if (txtmobile_direct.Text == string.Empty)
        {
            Response.Write("Please Enter Numbers");
            return;
        }

        if (txtMessage.Text == string.Empty)
        {
            Response.Write("Please Enter Your Message");
            return;
        }

        string authKey = "70740A9HJVjbP53e5cee9";
        string mobileNumber = numbers;
        string senderId = "NBCHOS";
        string message = HttpUtility.UrlEncode(sms);
        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}", "4");

        try
        {
            string sendSMSUri = "https://control.msg91.com/sendhttp.php";
            HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(sendSMSUri);
            UTF8Encoding encoding = new UTF8Encoding();
            byte[] data = encoding.GetBytes(sbPostData.ToString());
            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);
            }
            HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream());
            string responseString = reader.ReadToEnd();
            reader.Close();
            response.Close();
        }
        catch (SystemException ex)
        {
            Response.Write(ex.Message.ToString());
        }

       
    }
Posted
Updated 12-Sep-15 3:49am
v2
Comments
aarif moh shaikh 12-Sep-15 8:59am    
What error you got??
[no name] 12-Sep-15 9:51am    
"some error" can also mean your Screen is switched off... so please what is the error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900