1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14.

Saturday, February 20, 2010

Way2SMS send sms C# Code

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

12 comments:

  1. i want to implement this code in Windows Application so help me at vikram.beit@gmail.com

    ReplyDelete
  2. Iy's not show any error and not working

    ReplyDelete
  3. hi.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.
    --SIVA--

    ReplyDelete
  4. how can i use this code in vs2005 because u have used higher version???

    ReplyDelete
  5. i want to use this in the visual studio 2005.

    ReplyDelete
  6. Modified the Content to the following.

    content="HiddenAction=instantsms&login=&pass=&custid=&Action=custfrom1000000&sponserid=undefined&MobNo=" + ToMobile + "&textArea=" + mesg

    It is working fine. Tested in VB2005.

    ReplyDelete
  7. hi
    this code is working for my no for not my friend's number...

    ReplyDelete
  8. Send SMS using your mobile c# windows application

    http://codeglobe.blogspot.com/2010/02/way2sms-send-sms-c-code.html

    ReplyDelete
  9. Well code is nice I made a csharp file
    exported the namespace and on onclick event of button i wrote


    SmsSender sms = new SmsSender();
    sms.send(TextBox3.Text, TextBox4.Text,"phno_recipient", "message");

    ReplyDelete
  10. this will work for only Action element will be set
    in
    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

    ReplyDelete
  11. how to do it in windows application...?

    ReplyDelete

Related Posts with Thumbnails