我正在查询一个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
此时,我可以检索到网页文档,但我想知道服务器发送的 Content-Type 是什么。不幸的是,这并不总是与 bash 'file' 命令找到的 mime 类型相同。对于 .js 或 .css 文档,此 file 方法会失败。