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");
}
}
}
cochin IT solutions -web hosting web development cellphone applications business solutions seo services
Saturday, February 20, 2010
Subscribe to:
Post Comments (Atom)


i want to implement this code in Windows Application so help me at vikram.beit@gmail.com
ReplyDeleteIy's not show any error and not working
ReplyDeletehiiiiiiiiiiiiiii
ReplyDeletehi.i tried this code in windows vista home edition with VS2005. Its not showing any error and not working(recipient didnt get the sms). Pls help me.
ReplyDelete--SIVA--
how can i use this code in vs2005 because u have used higher version???
ReplyDeletei want to use this in the visual studio 2005.
ReplyDeleteModified the Content to the following.
ReplyDeletecontent="HiddenAction=instantsms&login=&pass=&custid=&Action=custfrom1000000&sponserid=undefined&MobNo=" + ToMobile + "&textArea=" + mesg
It is working fine. Tested in VB2005.
hi
ReplyDeletethis code is working for my no for not my friend's number...
Send SMS using your mobile c# windows application
ReplyDeletehttp://codeglobe.blogspot.com/2010/02/way2sms-send-sms-c-code.html
Well code is nice I made a csharp file
ReplyDeleteexported the namespace and on onclick event of button i wrote
SmsSender sms = new SmsSender();
sms.send(TextBox3.Text, TextBox4.Text,"phno_recipient", "message");
this will work for only Action element will be set
ReplyDeletein
content="HiddenAction=instantsms&login=&pass=&custid=&Action=custfrom1000000&sponserid=undefined&MobNo=" + ToMobile + "&textArea=" + mesg
other wise it wont work for you. you can find it source of
http://wwwd.way2sms.com/jsp/InstantSMS.jsp
how to do it in windows application...?
ReplyDelete