Skip to content

October 16, 2013

Sample Code for Send sms via Bulk SMS API Using C#

Signup from a bulk sms provider.and modify the code according to that http api link.
HTTP API for sending message to single no

http://domainname.com/sendsms?uname=yourUsername&pwd=yourPassword&senderid=yourSenderid&to=9444xxxxxx&msg=yourMessage&route=yourRoute

We Provide several api’s such as

  • HTTP API for sending message to multiple nos,
  • HTTP API for sending Scheduled message,
  • HTTP API for Checking credits left for given route,
  • HTTP API for Checking credits for all routes,
  • HTTP API for Checking Delivery report of sent SMS through HTTP API

Sample Code for Send sms via Bulk SMS API Using C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public string mobile
    {
        get;
        set;
    }
    public string message
    {
        get;
        set;
    }
    public string username
    {
        get;
        set;
    }
    public string password
    {
        get;
        set;
    }
    public string domian
    {
        get;
        set;
    }
    public string sender
    {
        get;
        set;
    }
    public string route
    {
        get;
        set;
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        try
        {
            mobile = txtMobile.Text;
            message = txtMessage.Text;
            username = txtName.Text;
            password = txtPassword.Text;
            sender = txtSenderId.Text;
            domian = txtDomain.Text;
            route = txtrout.Text;
            string result = apicall("http://" + domian + "/sendsms?uname=" + username + "&pwd=" + password + "&senderid=" + sender + "&to=" + mobile + "&msg=" + message+ "&route=" + route);

            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
        {
        }
    }
    public string apicall(string url)
    {
        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";
        }
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        txtName.Text = "";
        txtPassword.Text = "";
        txtDomain.Text = "";
        txtSenderId.Text = "";
        txtMobile.Text = "";
        txtMessage.Text = "";
    }
}

 

sms
Demo                    Download