【问题标题】:perl http request, how to truncate outputperl http请求,如何截断输出
【发布时间】:2012-10-11 18:05:13
【问题描述】:

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

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

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

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

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

【问题讨论】:

  • 您是否尝试查看HTTP::Response 文档?

标签: perl http get request truncate


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 1970-01-01
    • 2017-02-28
    • 1970-01-01
    相关资源
    最近更新 更多