通过Perl中的Way2sms自动发送短信

前端之家收集整理的这篇文章主要介绍了通过Perl中的Way2sms自动发送短信前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用Perl LWP通过Way2sms发送短信.登录部分成功,之后我将cookie保存到本地文件.登录后的欢迎页面显示发送短信链接,点击哪一个被重定向到另一个页面,其中有两个用于移动号码和短信文本的输入以及一个用于提交和发送短信的按钮. Firebug显示页面结构,如图所示.从Iframe网址和表单的操作属性,我构造了表单操作的绝对URL并相应地提交表单,并将cookie存储在文件中.但是,短信不会被发送.我在这做错了什么?代码如下. (两个文本输入的名称属性是正确的,通过观察Firebug中的源代码获取,尽管图像中未包含该代码)
use LWP::UserAgent;
open f,"> way2sms.txt";
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']);

解决方法

工作脚本:(测试于2012年9月6日下午3点到格林尼治标准时间5:30)
use LWP::UserAgent;
    use HTTP::Cookies;

    my $ua = LWP::UserAgent->new(agent=>"Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1");

    $ua->cookie_jar({ file => "/absolute/path/to/cookies.txt",autosave => 1 });
    # if windows,use \ instead of /

    # $ua->proxy(['http','ftp'],'http://localhost:9666/');

    # below line seems to have done the trick
    push @{ $ua->requests_redirectable },'POST';

    my $response = $ua->post(
            'http://site5.way2sms.com/Login1.action',{
            "username" => "1234567890",# set your username
            "password" => "passwd0123",# set your password
            "userLogin" => "yes","message" => "","mobileNo" => "",}
    );

    if($response->is_success && $response->decoded_content =~ /logout/i){ # you can have your name too in place of logout
            print "Logged in!\r\n";
    }

    my $mob = "1234567890"; # mobile to send message to
    my $mes = "Hello! 123."; # message

    my $smsresp = $ua->post(
            "http://site5.way2sms.com/quicksms.action",{
                    'Action' => 'dsf45asvd5','HiddenAction' => 'instantsms','catnamedis' => 'Birthday','chkall' => 'on','MobNo' => $mob,'textArea' => $mes,});

     if ($smsresp->is_success && $smsresp->decoded_content =~ /Submitted/i) {
         print "Sent!\r\n";
     }

附:我希望我可以获得过期的赏金O_o

猜你在找的Perl相关文章