Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 26th, 2012, 04:15 AM
Cupidvogel Cupidvogel is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 62 Cupidvogel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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']);   
Attached Images
File Type: png sms.png (311.4 KB, 22 views)

Last edited by Cupidvogel : August 26th, 2012 at 10:38 AM.

Reply With Quote
  #2  
Old August 26th, 2012, 08:07 AM
keath's Avatar
keath keath is offline
!~ /m$/
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: May 2004
Location: Reno, NV
Posts: 4,084 keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 49 m 56 sec
Reputation Power: 1809
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.
Comments on this post
Cupidvogel agrees!

Reply With Quote
  #3  
Old August 26th, 2012, 08:59 AM
Cupidvogel Cupidvogel is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 62 Cupidvogel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #4  
Old August 26th, 2012, 11:04 AM
keath's Avatar
keath keath is offline
!~ /m$/
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: May 2004
Location: Reno, NV
Posts: 4,084 keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 49 m 56 sec
Reputation Power: 1809
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;
 }

Reply With Quote
  #5  
Old August 26th, 2012, 11:16 AM
Cupidvogel Cupidvogel is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 62 Cupidvogel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Automating sms sending by through Way2sms in Perl

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap