http 响应头之location

<pre name="code" class="html">jrhmpt01:/root# cat login_yylc.pl 
use  LWP::UserAgent;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
use Net::Ping;  
use Socket;
use Net::SMTP;
use LWP;
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Headers;
use HTTP::Response;
use Encode;
use URI::Escape;
use URI::URL;
use Data::Dumper;
   my $ua = LWP::UserAgent->new;
   $ua->timeout(5);
   $ua->env_proxy;
   $ua->agent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0");
   my $cookie_jar = HTTP::Cookies->new(
       file=>'lwp_cookies.txt',
       autosave=>1,
       ignore_discard=>1);
       $ua->cookie_jar($cookie_jar);

#$var='https://licai.yingyinglicai.com/index.htm';
#<input type="hidden" id="token" name="token" value="3E79AB8CF9603A03DF74DDD6154A8BAD"/>

   my $var='https://licai.yingyinglicai.com/user/login.htm';
   my $response = $ua->get($var);
   $var= $response->decoded_content;
##<input type="hidden" id="token" name="token" value="7C84D7FD0889D23EAA8D266979552D2D"/>

if ($var =~/.*token"s+value="(.*?)"/.*/)
   {print "$1 is $1
";
   $token=$1;
   };

 my $login_url = 'https://licai.yingyinglicai.com/user/loginByPwd.do';
                
       my $res = $ua->post($login_url,{
                          'cell'=>18072xx2237,
                          'password'=>80xx5,
                          'token'=>$token
                                       },
                          'Host'=>'licai.yingyinglicai.com',
                           'User-Agent'=>'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0'   );
     my $homepage; 
     print "header-----------------
";
     print $res->header('Location');
     print "header-----------------
";


$1 is DC341A499F42389A5EA4841042C7C04F
header-----------------
http://licai.yingyinglicai.com/index.htm
header-----------------

$h->header( $field )
$h->header( $field => $value )
$h->header( $f1 => $v1, $f2 => $v2, ... )

获取或者设置 一个或者多个header字段的值,header 字段名($field)不是大小写敏感的。

为了使perl 用户生活更简单 需要避免引号在=>操作符前,你可以使用'_' 作为一个替代'-' 在header names


header()方法接收多个键值对,这意味着你可以更新多个fields在一个领域


Examples:

$header->header(MIME_Version => '1.0',
                User_Agent   => 'My-Web-Client/0.01');
$header->header(Accept => "text/html, text/plain, image/*");
$header->header(Accept => [qw(text/html text/plain image/*)]);
@accepts = $header->header('Accept');  # get multiple values
$accepts = $header->header('Accept');  # get values as a single string




响应头:
Connection	
keep-alive
Content-Language	
zh-CN
Content-Length	
0
Date	
Wed, 03 Aug 2016 12:22:20 GMT
Location	
http://licai.yingyinglicai.com/index.htm
Server	
nginx
Set-Cookie	
YYLCSJSESSIONID=f9d49ab5-acc4-4518-a6ab-ec73a6ae39eb; Domain=yingyinglicai.com; Expires=Wed, 03-Aug-2016
 12:52:20 GMT; Path=/


   print $res->header('Server');  返回nginx




   

原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6199438.html