gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 13:28:15 28 4
gpt4 key购买 nike

我正在尝试使用Perl LWP通过Way2sms发送短信。登录部分成功,然后将cookie保存到本地文件。登录后的欢迎页面显示一个发送SMS 链接,单击该链接将重定向到另一页,其中包含用于输入手机号码和短信文本的两个输入以及一个用于提交和发送短信的按钮。 Firebug揭示了如图所示的页面结构。根据Iframe网址和表单的action属性,我构造了表单操作的绝对URL,并使用存储在文件中的cookie相应地提交了表单。但是,不会发送短信。我在这里做错了什么?代码如下。 (两个文本输入的name属性是正确的,通过观察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日格林尼治标准时间+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";
}

P.S.我希望我能得到那个过期的赏金O_o :)

关于perl - 通过Perl中的Way2sms自动发送短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12128770/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com