C# Code Examples

Get Started With Ez Texting's HTTP SMS API Using Our C# Code Samples

Sending SMS Messages - Code Examples:

Send A Single Message

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;

namespace ex1
{
    class Program
    {
        static void Main(string[] args)
        {
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.eztexting.com/api/sending/");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("user=exampleuser&pass=texting&phonenumber=2125551234&subject=test&message=test message&express=1");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
            {
                using (Stream responseStream = r.GetResponseStream())
                {
                    using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        ret = readStream.ReadToEnd();
                    }
                }
            }
            System.Console.Out.WriteLine(ret); /* result of API call*/

        }
    }
}

Send Multiple Messages

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;

namespace ex2
{
    class Program
    {
        static void Main(string[] args)
        {
            var messages = new[] {
                                 new {phone = "3616885766", subj = "test", message = "test message"},
                                 new {phone = "3616885766", subj = "test2", message = "test message2"},
                                 new {phone = "3616885766", subj = "test3", message = "test message3"}
                             };

            foreach (var msg in messages)
            {
                string ret = string.Empty;
                WebRequest w = WebRequest.Create("https://app.eztexting.com/api/sending/");
                w.Method = "POST";
                w.ContentType = "application/x-www-form-urlencoded";
                using (Stream writeStream = w.GetRequestStream())
                {
                    byte[] bytes = Encoding.UTF8.GetBytes("user=exampleuser&pass=texting&phonenumber=" + msg.phone + "&subject=" + msg.subj + "&message=" + msg.message + "&express=1");
                    writeStream.Write(bytes, 0, bytes.Length);
                }
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    using (Stream responseStream = r.GetResponseStream())
                    {
                        using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                        {
                            ret = readStream.ReadToEnd();
                        }
                    }
                }
                System.Console.Out.WriteLine(ret); /* result of API call*/
            }
        }
    }
}

Receiving Keyword Submissions - Code Examples:


ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string message = Request["Message"];
        string mysender = Request["PhoneNumber"];
        if (string.IsNullOrEmpty(mysender))
        {
            Response.Write("The C# script is waiting for messages");
        }
        else
        {
            //Save incoming messages
            using (StreamWriter sw = new StreamWriter("receivelog.txt", true))
            {
                sw.WriteLine(mysender);
            }


            //Return a response SMS message
            string responsetext = "Thank you for the message!";
            Response.Write("{SMS:TEXT}{}{}{" + mysender + "}{" + responsetext + "}");
        }
    }
}

Check Credit Balance - Code Examples:

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;

namespace ex4
{
    class Program
    {
        static void Main(string[] args)
        {
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.eztexting.com/api/credits/check/");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("user=exampleuser&pass=texting");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
            {
                using (Stream responseStream = r.GetResponseStream())
                {
                    using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        ret = readStream.ReadToEnd();
                    }
                }
            }
            System.Console.Out.WriteLine(ret); /* result of API call*/

        }
    }
}

Check Keyword Availability - Code Examples:

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;

namespace ex5
{
    class Program
    {
        static void Main(string[] args)
        {
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.eztexting.com/api/keyword/check/");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("user=exampleuser&pass=texting&keyword=userkeyword");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
            {
                using (Stream responseStream = r.GetResponseStream())
                {
                    using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        ret = readStream.ReadToEnd();
                    }
                }
            }
            System.Console.Out.WriteLine(ret); /* result of API call*/
        }
    }
}

Buy More Credits - Code Examples:

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.Text;
using System.IO;

namespace ex6
{
    class Program
    {
        static void Main(string[] args)
        {
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.eztexting.com/api/credits/buy/");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("user=exampleuser&pass=texting&credits=5&firstname=firstname&lastname=lastname&address=address&city=newyork&state=ny&zip=08902&country=usa&type=visa&ccnumber=rIhLJUiXl8M0JIcrelxH9A&cccode=111&expm=11&expy=12");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
            {
                using (Stream responseStream = r.GetResponseStream())
                {
                    using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        ret = readStream.ReadToEnd();
                    }
                }
            }
            System.Console.Out.WriteLine(ret); /* result of API call*/
        }
    }
}

Rent a Keyword: - Code Examples

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;

namespace ex7
{
    class Program
    {
        static void Main(string[] args)
        {
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.eztexting.com/api/keyword/rent/");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("user=exampleuser&pass=texting&keyword=keywordtorent&firstname=firstname&lastname=lastname&address=address&city=new york&state=ny&zip=08902&country=usa&type=visa&ccnumber=rIhLJUiXl8M0JIcrelxH9A&expm=11&expy=2012");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
            {
                using (Stream responseStream = r.GetResponseStream())
                {
                    using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        ret = readStream.ReadToEnd();
                    }
                }
            }
            System.Console.Out.WriteLine(ret); /* result of API call*/
        }
    }
}

Configure a Keyword - Code Examples:
 

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;

namespace ex8
{
    class Program
    {
        static void Main(string[] args)
        {
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.eztexting.com/api/keyword/setup/");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("user=exampleuser&pass=texting&keyword=misha5&group=Test Canada&autoreply=autoreply&url=http://test.com/test");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
            {
                using (Stream responseStream = r.GetResponseStream())
                {
                    using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        ret = readStream.ReadToEnd();
                    }
                }
            }
            System.Console.Out.WriteLine(ret); /* result of API call*/
        }
    }
}

Voice Broadcast - Code Examples:

(Single Number)

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.Text;
using System.IO;

namespace ex9
{
    class Program
    {
        static void Main(string[] args)
        {
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.eztexting.com/api/voicemessages/");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("user=exampleuser&pass=texting&phonenumbers=3616885766&soundsource=http://work5.exampleuser.com/EzTexting/test.wav&callerid=3616885766");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
            {
                using (Stream responseStream = r.GetResponseStream())
                {
                    using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        ret = readStream.ReadToEnd();
                    }
                }
            }
            System.Console.Out.WriteLine(ret); /* result of API call*/
        }
    }
}

(An Array Of Numbers)

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.Text;
using System.IO;

namespace ex10
{
    class Program
    {
        static void Main(string[] args)
        {
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.eztexting.com/api/voicemessages/");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("user=exampleuser&pass=texting&phonenumbers[]=3616885766&phonenumbers[]=3616885766&phonenumbers[]=3616885766&soundfile=test.wav&callerid=3616885766");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
            {
                using (Stream responseStream = r.GetResponseStream())
                {
                    using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        ret = readStream.ReadToEnd();
                    }
                }
            }
            System.Console.Out.WriteLine(ret); /* result of API call*/
        }
    }
}

Receiving Inbox Message Replies - Code Examples:


ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;


public partial class ex11 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string message = Request["message"];
        string mysender = Request["from"];
        if (!string.IsNullOrEmpty(mysender))
        {
            //Save incoming messages
            using (StreamWriter sw = new StreamWriter("forwardlog.txt", true))
            {
                sw.WriteLine(mysender);
            }
        }
    }
}

Carrier Lookup - Code Examples:

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.Text;
using System.IO;

namespace ex12
{
    class Program
    {
        static void Main(string[] args)
        {
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.eztexting.com/api/lookup/");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("user=exampleuser&pass=texting&phonenumber=3616885766");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
            {
                using (Stream responseStream = r.GetResponseStream())
                {
                    using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        ret = readStream.ReadToEnd();
                    }
                }
            }
            System.Console.Out.WriteLine(ret); /* result of API call*/
        }
    }
}