Can't Get Enough RSS 2.0
 Thursday, December 20, 2007

I use a website provided by the mobile phone company to send SMS messages, and charge it to my mobile phone, good to send bulk messages to friends and family.

I thought about using an automated method to send SMS to make it easier, I asked the mobile phone company if they provide something like a WebAPI or SMPP, but they don't.

So... I thought about using their form, and here come the greate HttpWebRequest and HttpWebResponse.

 

First I opened the login page... opened the page source, search for all form fields, login id, password and hidden fields.

Then I opened the Send SMS page... and did the same.

Now writing a test page:

protected void Page_Load(object sender, EventArgs e)

{

// Login Page

Uri uri = new Uri("http://WebSite/index.php");

// Login Form Fields

string data = "mo=login";

data += "&passwd=password";

data += "&login=1";

// Create a new instance of the CookieContainer

CookieContainer cookieContainer = new CookieContainer();

if (uri.Scheme == Uri.UriSchemeHttp)

{

// Create an instance of HttpWebRequest

HttpWebRequest request = HttpWebRequest.Create(uri) as HttpWebRequest;

// Preserve Cookies that have login information

request.CookieContainer = cookieContainer;

// Method = Post

request.Method = WebRequestMethods.Http.Post;

// Data Length & Content Type

request.ContentLength = data.Length;

request.ContentType = "application/x-www-form-urlencoded";

// Write Data to stream, this will send data to the website but will not fill the CookieContainer

StreamWriter writer = new StreamWriter(request.GetRequestStream());

writer.Write(data);

writer.Close();

// Get Response from website to fill the CookieContainer

request.GetResponse();

}

 

 

// Do the same here, and submitting the preserved cookies

uri = new Uri("http://WebSite/myo/schedulemsg.php");

data = "srcMSISDN=";

data += "&CustomerId=";

data += "&strRawText1=";

data += "&pagename=batsms2.php";

data += "&smsmode=web2sms";

data += "&dstMSISDN=";

data += "&requestType=WEB2SMS";

data += "&source=WEB";

data += "&message=Messsgae to send";

data += "&characters=1";

data += "&coding=0";

data += "&when=now";

data += "&schdate=";

data += "&hh=00";

data += "&mm=00";

data += "&send=Send";

if (uri.Scheme == Uri.UriSchemeHttp)

{

HttpWebRequest request = HttpWebRequest.Create(uri) as HttpWebRequest;

// Submit preserved cookies

request.CookieContainer = cookieContainer;

request.Method = WebRequestMethods.Http.Post;

request.ContentLength = data.Length;

request.ContentType = "application/x-www-form-urlencoded";

StreamWriter writer = new StreamWriter(request.GetRequestStream());

writer.Write(data);

writer.Close();

// Create an instance of the response to check if the message was sent

HttpWebResponse response = request.GetResponse() as HttpWebResponse;

StreamReader reader = new StreamReader(response.GetResponseStream());

string tmp = reader.ReadToEnd();

response.Close();

if (tmp.IndexOf("Message was sent successfully !.") > 0)

Label1.Text = "Message was sent successfully !.";

else

{

Label1.Text = "Confirmation Message was not received.";

}

}

}

 

It is working :D as expected.

Thursday, December 20, 2007 3:24:22 PM UTC  #    Comments [0] -
ASP.NET | C#
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
Navigation
Categories
Archive
<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Ghazi Sarhan
Sign In
Statistics
Total Posts: 13
This Year: 0
This Month: 0
This Week: 0
Comments: 4
Themes
Pick a theme:
All Content © 2010, Ghazi Sarhan
DasBlog theme 'Business' created by Christoph De Baene (delarou)