Perl测试(自动化)检查Cookies属性并显示通过或失败

时间:2013-07-03 07:31:55

标签: perl automation

如何编写Perl Module程序来检查安全cookie或Httponly标志的cookie属性,并使用测试模块显示结果是否包含secure和Httponly标志.Below是Cookie的代码。请问有人可以给代码。

use strict; 
use LWP::simple;
use LWP::UserAgent; 
use HTTP::Request;  

my $URL = 'https://www.gmail.com/'; 

my $ua = LWP::UserAgent->new();  
my $header = HTTP::Request->new(GET => $URL);  
my $request = HTTP::Request->new('GET', $URL, $header);  
my $response =  $ua->request($request); 


print $_ foreach @ {$response->headers()->{'set-cookie'}};

1 个答案:

答案 0 :(得分:0)

以下是一些阅读:http://lwp.interglacial.com/ch11_01.htm

它会将cookie保存到文件中,然后您可以检查该文件:

use HTTP::Cookies;
my $cookie_jar = HTTP::Cookies->new(
   file     => "/some/where/cookies.lwp",
   autosave => 1,
);
my $browser = LWP::UserAgent->new;
$browser->cookie_jar( $cookie_jar );