2

I am trying to automate sms sending through Way2sms in Perl LWP. I am able to login successfully. Then I click the Send SMS link in the browser to go the sms-sending page. From there, based upon the page url and the url of the iframe within which the sms fields are located, I try to construct the absolute URL of the page to which the form should be posted, and post it with the correct parameters (you can see it all in the image). However, the sms isn't being sent. Can anybody tell me what am I doing wrong here? (There is a similar module in CPAN which accomplishes this through Mechanize, I am trying a different approach)

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 => $mob,
        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']);
if ( $smsresp->is_redirect ) {
   $smsresp = $ua->post($smsresp->header('Location'),[MobNo=>$mob,textArea=>'Hello World']);
   }

enter image description here

SexyBeast
  • 7,913
  • 28
  • 108
  • 196
  • Take a look at the exact post requests using firebug (I can see you have it running in the screen dump). Since the remote website may have various security policies, the cause of this issue can be many things, so doing a side by side comparisons of the two requests is the only way to get an idea about what is going wrong. – mzedeler Oct 15 '12 at 18:54

1 Answers1

0

Here is an indirect answer that may help you out:

  1. If you have to use this website, try using something like CasperJS. There may be some JavaScript magic that needs to happen.
  2. Maybe you could use something like Google Voice or some other smarter service to automate send text messages. Looks like someone on CPAN already has a sweet Google::Voice module for this.
thealexbaron
  • 1,558
  • 1
  • 11
  • 25