perl http请求,如何截断输出

时间:2012-10-11 18:05:14

标签: perl http get request truncate

我正在尝试使用perl来在线阅读文本文件,使用如下调用:

$output = $ua->request($req)->as_string;

问题是输出中有很多我不想要的垃圾,例如。

HTTP/1.1 200 OK
Connection: close
Date: 
etc...

有没有办法截断输出,所以我只得到文件的内容?

1 个答案:

答案 0 :(得分:1)

问题是你只是从LWP::UserAgent获取响应对象并将其作为字符串转储。如果您想获得内容:

# Get the response
$response = $ua->request($req);
# Get the content portion of the response
$output = $response->content;

黑白分明:https://metacpan.org/pod/HTTP::Request