Friday 14 December 2012

Send sms using API and sms gateway


It is very simple code to do this . use api http request for doing that . For this you should have enough sms credit in your account  with a registered account with sms.scibero.com.

Code

======


public string apicall(string url)  // API Push
    {
        HttpWebRequest httpreq = (HttpWebRequest)WebRequest.Create(url);

        try
        {

            HttpWebResponse httpres = (HttpWebResponse)httpreq.GetResponse();

            StreamReader sr = new StreamReader(httpres.GetResponseStream());

            string results = sr.ReadToEnd();

            sr.Close();
            return results;



        }
        catch
        {
            return "0";
        }
    }




public void SendSMS()
    {

        try
        {
           
            mobile = "to number";
            message2 = "Your sms here '";
            username = "your user name";
            password = "your pwd";
            domian = "sms.scibero.com";
            senderid = "sender";
            string result = apicall("http://" + domian + "/pushsms.php?username=" + username + "&password=" + password + "&sender=" + senderid + "&to=" + mobile + "&message=" + message2);

            if (!result.StartsWith("Wrong Username or Password"))
            {
                //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('Message Sent')", true);
            }
            else
            {
               // ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('Message Sending Failed')", true);
            }

        }
        catch
        {
        }
    }

No comments:

Post a Comment