curl 返回响应头

demo:/root# curl -i baidu.com
HTTP/1.1 200 OK
Date: Wed, 27 Jul 2016 08:50:03 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: Keep-Alive
Vary: Accept-Encoding
Set-Cookie: BAIDUID=0012CCC7FDB7C71CCFD7564DF73CCCAA:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Set-Cookie: BIDUPSID=0012CCC7FDB7C71CCFD7564DF73CCCAA; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Set-Cookie: PSTM=1469609403; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Set-Cookie: BDSVRTM=0; path=/
Set-Cookie: BD_HOME=0; path=/
Set-Cookie: H_PS_PSSID=1446_18240_20416_19861_15954_11956_20705_20696; path=/; domain=.baidu.com
P3P: CP=" OTI DSP COR IVA OUR IND COM "
Cache-Control: private
Cxy_all: baidu+938d6eaf9bc28d04fd2b7d2ebd708c74
Expires: Wed, 27 Jul 2016 08:49:57 GMT
X-Powered-By: HPHP
Server: BWS/1.1
X-UA-Compatible: IE=Edge,chrome=1
BDPAGETYPE: 1


head($url)
Get document headers. Returns the following 5 values if successful: ($content_type, $document_length, $modified_time, $expires, $server)

Returns an empty list if it fails. In scalar context returns TRUE if successful.


得到document headers. 返回下面5个值如果成功的话 

($content_type, $document_length, $modified_time, $expires, $server)


[root@dr-mysql01 0727]# cat a1.pl 
use LWP::Simple; 
my $host='http://www.baidu.com';
($content_type, $document_length, $modified_time, $expires, $server)= head($host);
  print "\$content_type is $content_type\n";
  print "\$document_length is $document_length\n";
  print "\$modified_time is $modified_time\n";
  print "\$expires is $expires\n";
  print "\$server is $server\n";
[root@dr-mysql01 0727]# perl a1.pl 
$content_type is text/html
$document_length is 277
$modified_time is 1465786250
$expires is 
$server is bfe/1.0.8.14

posted @ 2016-07-27 16:52  czcb  阅读(1915)  评论(0编辑  收藏  举报