帮忙分析一下这个perl程序 问什么post不成功?

软件和网站开发以及相关技术探讨
回复
wbc1223
帖子: 1
注册时间: 2011-02-16 0:00
送出感谢: 0
接收感谢: 0

帮忙分析一下这个perl程序 问什么post不成功?

#1

帖子 wbc1223 » 2011-02-16 0:06

#程序作用:
#1、登陆 http://www.gongkong365.com/bbs/post.php 用户名:wbc1223 账号:831223
#2、向http://www.gongkong365.com/bbs/read.php?tid=84 ... &这个帖子回一个内容
# 内容:"Thank you very much"
use LWP;
use HTTP::Cookies;
use LWP::UserAgent;


my $ua = LWP::UserAgent->new( );
my $cookie_jar = HTTP::Cookies->new(autosave=>1 );
$ua->cookie_jar( $cookie_jar);


@netscape_like_headers = (
accept=>"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*",
Accept-Encoding=>"gzip, deflate",
Accept-Language=>"zh-cn",
Cache-Control=>"no-cache",
Connection=>"Keep-Alive",
Content-Length=>"242",
Content-Type=>"application/x-www-form-urlencoded",
Cookie=>"b8bac_c_stamp=1297781858; b8bac_lastpos=T8406; AJSTAT_ok_pages=5; AJSTAT_ok_times=1; b8bac_olid=4904; b8bac_readlog=%2C8406%2C; b8bac_jobpop=0; b8bac_winduser=AFQFAQpsUFJSXAUAUwAGAVUHVwVUUgoBBlYHWAVTBgBVVFJRUVQ8; b8bac_ck_info=%2F%09; b8bac_lastvisit=0%091297781858%09%2Fbbs%2Fread.php%3Ftid%3D8406%26toread%3D1",
Host=>"www.gongkong365.com",
Referer=>"http://www.gongkong365.com/bbs/read.php?tid=8406&page=e&",
User-Agent=>"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; CIBA)",
);

login();#登陆 账户名:wbc1223 密码:831223

#$ua->cookie_jar( $cookie_jar);

my $response = $ua->post(
"http://www.gongkong365.com/bbs/post.php",
[
"_hexie"=>"54ddd1de",
"action"=>"reply",
"atc_autourl"=>"1",
"atc_content"=>"Thank you very much",
"atc_convert"=>"1",
"atc_desc1"=>"",
"atc_title"=>"Re:西门子 S7-300 PLC模拟量转换",
"atc_usesign"=>"1",
"attachment_1"=>"",
"fid"=>"81",
"step"=>"2",
"tid"=>"8406",
"verify"=>"a07f801f"
],
@netscape_like_headers
);


print $response->status_line;


open FILEHANDLE, ">suzhou.txt";
print FILEHANDLE $response->{_content};
close FILEHANDLE;



sub login
{
my $browser = LWP::UserAgent->new( );

my @netscape_like_headers = (
accept=>"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*",
Accept-Encoding=>"gzip, deflate",
Accept-Language=>"zh-cn",
Cache-Control=>"no-cache",
Connection=>"Keep-Alive",
Content-Type=>"application/x-www-form-urlencoded",
Host=>"www.gongkong365.com",
Referer=>"http://www.gongkong365.com/bbs/index.php",
User-Agent=>"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; CIBA)",
);


my $response = $browser->post(
"http://www.gongkong365.com/bbs/login.php",
[
answer=>"",
cktime=>"31536000",
customquest=>"",
jumpurl=>"http://www.gongkong365.com/bbs/index.php",
lgt=>"0",
pwpwd=>"831223",
pwuser=>"wbc1223",
question=>"0",
step=>"2",
],
@netscape_like_headers
);

$cookie_jar->extract_cookies($response);
$ua->cookie_jar($cookie_jar);#每次完了必须往内存写一下 否则丢失cookie

if(!$response->is_success)
{
die "登录错误!\n";
}
}
附件
帮忙分析一下这个perl lwp程序.rar
上面的代码
(1.41 KiB) 下载 17 次
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙
送出感谢: 4 次
接收感谢: 256 次

Re: 帮忙分析一下这个perl程序 问什么post不成功?

#2

帖子 eexpress » 2011-02-16 10:02

print $response->decoded_content;
而不是
die "登录错误!\n";

这样才能分析下啊
● 鸣学
回复

回到 “软件/网站开发”