How to send SMS from asp.net web application?
Is it necessary to buy from any provider?
Is there any limitation of number of SMS can be sent?
Should send
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
namespace SMSAPI
{
class SmsSender
{
void send(string uid, string pwd, string no, string msg)
{
String content = "username="+uid+"&password="+pwd;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://wwwa.way2sms.com/auth.cl");
request.KeepAlive = false;
byte[] byteArray = Encoding.UTF8.GetBytes(content);
CookieContainer cookies = new CookieContainer();
request.CookieContainer = cookies;
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5";
request.ContentLength = byteArray.Length;
request.ContentType = "application/x-www-form-urlencoded";
request.Accept = "*/*";
request.Referer = "http://wwwg.way2sms.com//entry.jsp";
request.Method = "POST";
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
foreach (Cookie cook in response.Cookies)
{
cookies.Add(cook);
}
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string serverData = reader.ReadToEnd();
reader.Close();
content = "custid=undefined&HiddenAction=instantsms&Action=custfrom450000&login=&pass=&MobNo="+no+"&textArea="+msg;
request = (HttpWebRequest)WebRequest.Create("http://wwwa.way2sms.com/FirstServletsms?custid=");
byteArray = Encoding.UTF8.GetBytes(content);
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5";
request.ContentLength = byteArray.Length;
request.ContentType = "application/x-www-form-urlencoded";
request.Accept = "*/*";
request.CookieContainer = cookies;
request.Method = "POST";
dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
reader = new StreamReader(stream);
serverData = reader.ReadToEnd();
reader.Close();
request = (HttpWebRequest)WebRequest.Create("http://wwwa.way2sms.com/jsp/logout.jsp");
byteArray = Encoding.UTF8.GetBytes(content);
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5";
request.ContentLength = byteArray.Length;
request.ContentType = "application/x-www-form-urlencoded";
request.Accept = "*/*";
request.CookieContainer = cookies;
request.Method = "POST";
dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
reader = new StreamReader(stream);
serverData = reader.ReadToEnd();
reader.Close();
}
catch (ArgumentException e)
{
Console.WriteLine("arg exception");
Console.Read();
}
catch (WebException e)
{
Console.WriteLine("web exception");
Console.Read();
}
catch (Exception e)
{
Console.WriteLine("exception");
Console.Read();
}
}
static void Main(string[] args)
{
SmsSender sms = new SmsSender();
sms.send("username", "password", "phno_recipient", "message");
}
}
}