The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
Automating sms sending by through Way2sms in Perl
Discuss Automating sms sending by through Way2sms in Perl in the Perl Programming forum on Dev Shed. Automating sms sending by through Way2sms in Perl Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 26th, 2012, 04:15 AM
|
|
Contributing User
|
|
Join Date: Mar 2012
Posts: 62
Time spent in forums: 4 h 38 m 22 sec
Reputation Power: 2
|
|
|
Automating sms sending by through Way2sms in Perl
I am trying to send sms through Way2sms using Perl LWP. The login part is being successful, after which I save the cookies to a local file. The welcome page after being logged in shows a Send SMS link, clicking on which one is redirected to another page with two inputs for mobile number and sms text and a button for submitting and sending the sms. Firebug reveals the page structure as shown in the figure. From the Iframe url and the form's action attribute, I constructed the form action's absolute URL and submit the form accordingly, with the cookie stored in the file. However, the sms isn't sent. What I am doing wrong here? The code is as follows. (The name attributes for the two text inputs are correct, taken by observing the source code in Firebug, although that's not included in the image)
Code:
use LWP::UserAgent;
use HTTP::Cookies;
my $cookie_jar = HTTP::Cookies->new(
file => "cookies.txt",
autosave => 1,
);
my $ua = LWP::UserAgent->new(
agent =>
'Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
cookie_jar => $cookie_jar,
);
my $response = $ua->post(
'http://site2.way2sms.com/contentt/bar/Login1.action',
{
username => $user,
password => $pass,
}
);
my $ocookie_jar = HTTP::Cookies->new(
file => "cookies.txt",
);
if ( $response->is_redirect ) {
$response = $ua->get( $response->header('Location') );
print 5 if $response->decoded_content =~ /Kaustav Mukherjee/i; #prints 5 if the resultant page contains my name, showing that the login is successful
}
my $smspage = LWP::UserAgent->new(agent =>
'Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
cookie_jar => $ocookie_jar);
my $smsresp = $smspage->post("http://site5.way2sms.com/jsp/quicksms.action",[MobNo=>$mob,textArea=>'Hello World']);
Last edited by Cupidvogel : August 26th, 2012 at 10:38 AM.
|

August 26th, 2012, 08:07 AM
|
 |
!~ /m$/
|
|
Join Date: May 2004
Location: Reno, NV
|
|
|
The point of accepting cookies is that your browser will store information about a site, and be able to give that information back to a server when you make another request so the server can recognize the identity you provided earlier.
Imagine opening Internet Explorer and logging in to a website, and then right after that opening Firefox and trying to visit that same website. The server would need you to log in again. It has no idea you are the same person who logged in a moment before.
That's what you've done in the script. You created a cookie jar and put it in your browser (UserAgent), then created another cookie jar after posting, and then created a new browser to attempt to reach a restricted page.
Also, check the first URL. Might not be valid.
|

August 26th, 2012, 08:59 AM
|
|
Contributing User
|
|
Join Date: Mar 2012
Posts: 62
Time spent in forums: 4 h 38 m 22 sec
Reputation Power: 2
|
|
No no, the first URL may look invalid, but it is valid. I was testing it, whatever I insert between site2.way2sms.com and Login1.action, the page is always redirected. I noted what you said and revised the code. Still the sms is not being sent!
Code:
use LWP::UserAgent;
use HTTP::Cookies;
my $cookie_jar = HTTP::Cookies->new(
file => "cookies.txt",
autosave => 1,
);
my $ua = LWP::UserAgent->new(
agent =>
'Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
cookie_jar => $cookie_jar,
);
my $response = $ua->post(
'http://site2.way2sms.com/contentt/bar/Login1.action',
{
username => $user,
password => $pass,
}
);
if ( $response->is_redirect ) {
$response = $ua->get( $response->header('Location') );
print 5 if $response->decoded_content =~ /Kaustav Mukherjee/i; #prints it, showing that the login is successful
}
my $smsresp = $ua->post("http://site5.way2sms.com/jsp/quicksms.action",[MobNo=>$mob,textArea=>'Hello World']);
Last edited by Cupidvogel : August 26th, 2012 at 09:09 AM.
|

August 26th, 2012, 11:04 AM
|
 |
!~ /m$/
|
|
Join Date: May 2004
Location: Reno, NV
|
|
I don't have an account there, so I can't test any of it. The reason I asked about the URL is the two T's at the end of the word 'contentt'
Code:
http://site2.way2sms.com/contentt/bar/Login1.action
I wasn't able to get to that URL with a browser, so it didn't seem valid, but if you said you logged in then fine.
But you will need to examine that second form very carefully. It may need more than just the data you want to send. Often times there are hidden fields embedded that will need to be submitted back.
Check the response object and see what went wrong:
Code:
my $smsresp = $ua->post("http://site5.way2sms.com/jsp/quicksms.action",[MobNo=>$mob,textArea=>'Hello World']);
if ($smsresp->is_success) {
print $smsresp->content; # you can print this to a file if you want to check the page in a text editor
} else {
die $smsresp->status_line;
}
|

August 26th, 2012, 11:16 AM
|
|
Contributing User
|
|
Join Date: Mar 2012
Posts: 62
Time spent in forums: 4 h 38 m 22 sec
Reputation Power: 2
|
|
|
I just did, and got a redirected status line. So I used the redirection method which I used with the first login method here also. Now I am getting a status 200 OK message, but still no sms. Is there any way of sending you a message? Then I can send you the login details, you can check with that.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|