模拟浏览器的POST请求 z

本文介绍了一个使用 Perl 编写的 CGI 脚本示例,该脚本通过 LWP 模块实现网页登录及状态页面获取的功能。脚本展示了如何设置 UserAgent、管理 Cookies 以及发送 HTTP 请求。

#!/usr/bin/perl
#By yzjboy
use LWP::UserAgent;
use HTTP::Cookies;
my $datadir = $ENV{"DOCUMENT_ROOT"}."/cgi-bin";

################################## 
my $url = 'http://www.serverq.com/logon.asp?login=xxxxx&password=xxxx'; 
my $ua = LWP::UserAgent->new;  
my $cookie_jar = HTTP::Cookies->new( file => "$datadir/teqcookie.txt", autosave => 1 ); 
$ua->cookie_jar($cookie_jar); 
$ua->agent( "Explorer" );  
my $request = HTTP::Request->new(GET => $url); 
my $response = $ua->request($request); 
$cookie_jar->extract_cookies($response);  
$ua->cookie_jar($cookie_jar);
# bis hierhin klappt alles... ich würde ne korrekte einloggseite bekommen wenn ich sie # ausgebe...
# auch der Cookie is erstellt  
$url = 'http://www.server.com/status.asp';   
$request = HTTP::Request->new(GET => $url); 
$cookie_jar->add_cookie_header($request); 
my $response = $ua->request($request);   
my $content = $response->content();    
print "$content"; 
exit;


<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值