加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Perl LWP :: useragent捕获服务器响应头

发布时间:2020-12-15 23:27:10 所属栏目:大数据 来源:网络整理
导读:我正在查询文档的Web服务器,我想捕获文档和相关的服务器响应头(特别是Content-Type:…).我无法找到如何阅读标题.以下是我的Perl脚本中的一些代码片段,为了清楚起见,我留下了错误检查: use LWP::UserAgent;my $ua = LWP::UserAgent-new;$ua-agent( 'require
我正在查询文档的Web服务器,我想捕获文档和相关的服务器响应头(特别是Content-Type:…).我无法找到如何阅读标题.以下是我的Perl脚本中的一些代码片段,为了清楚起见,我留下了错误检查:

use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent( 'requiredCustomUserAgent' ); # I'm required to set a custom user agent
$imageData = $response->content;         # This is the received document

所以此时我可以检索Web文档,但我想知道服务器使用它发送的Content-Type.不幸的是,这并不总是与bash’file’命令找到的mime类型相同.在.js或.css文档的情况下,此文件方法失败.

解决方法

http://search.cpan.org/perldoc?HTTP::Response

use LWP::UserAgent;
my $ua = new LWP::UserAgent;
my $response = $ua->get("http://google.co.uk");

print $response->headers()->as_string;
print $response->header('content-type');

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读