Print Friendly and PDF
In this Article am describing how to integrate SMS API in C# that can send SMS to your mobile phone within Pakistan. First go to this website and signup here Here are the simple Steps that you follow : First Launch a visual studio Create a console Application in visual studio After that first added assembly reference into your project using System.Net; using System.Web;
In this Article am describing how to integrate SMS API in C#  that can send SMS to your mobile phone within Pakistan.
 First go to this website and signup here

Here are the simple Steps that you follow  :

  1. First Launch a visual studio 
  2. Create a console Application in visual studio 
  3. After that first added assembly reference into your project

using System.Net;
using System.Web;
Here is Implementation

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            string MyUsername = "xxxx"; //Your Username At Sendpk.com 
            string MyPassword = "xxxx"; //Your Password At Sendpk.com 
            string toNumber = "xxxxx"; //Recepient cell phone number with country code 
            string Masking = "Tech Spider"; //Your Company Brand Name 
            string MessageText = "Application Done";
            string jsonResponse = SendSMS(Masking, toNumber, MessageText, MyUsername, MyPassword);
            Console.Write(jsonResponse);
            //Console.Read(); //to keep console window open if trying in visual studio 
            Console.ReadLine();
        }
        public static string SendSMS(string Masking, string toNumber, string MessageText, string MyUsername, string MyPassword)
        {
            String URI = "http://Sendpk.com" +
            "/api/sms.php?" +
            "username=" + MyUsername +
            "&password=" + MyPassword +
            "&sender=" + Masking +
            "&mobile=" + toNumber +
            "&message=" + Uri.UnescapeDataString(MessageText); // Visual Studio 10-15 
          
            try
            {
                WebRequest req = WebRequest.Create(URI);
                WebResponse resp = req.GetResponse();
                var sr = new System.IO.StreamReader(resp.GetResponseStream());
                return sr.ReadToEnd().Trim();
            }
            catch (WebException ex)
            {
                var httpWebResponse = ex.Response as HttpWebResponse;
                if (httpWebResponse != null)
                {
                    switch (httpWebResponse.StatusCode)
                    {
                        case HttpStatusCode.NotFound:
                            return "404:URL not found :" + URI;
                            break;
                        case HttpStatusCode.BadRequest:
                            return "400:Bad Request";
                            break;
                        default:
                            return httpWebResponse.StatusCode.ToString();
                    }
                }
            }
            return null;
            
        }
    
    }
   
    }
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

4 comments:

  1. Hello Zubair saif,
    how are you?
    bro i face a one error, and i don't know how to solve.
    this code return [ Please Type Send ID]

    ReplyDelete
  2. Nice work Buddy ... Thanks a lot

    ReplyDelete
  3. Thats of great help bro.
    Loved it :)

    ReplyDelete