簡體   English   中英

如何在Perl中使用LWP :: UserAgent獲取HTTP響應的主體?

[英]How can I get the body of an HTTP response using LWP::UserAgent in Perl?

我發現LWP::UserAgent->request()的返回包含HTTP響應的頭部和主體。 我只需要響應的主體做一些解析,那我該怎么辦?

require LWP::UserAgent;

my $ua = LWP::UserAgent->new;

my $response = $ua->get('http://search.cpan.org/');

if ($response->is_success) {

    print $response->decoded_content;  # or whatever
}
else {
    die $response->status_line;
}

response->decoded_content將返回響應的主體。

request方法( 根據手冊 )返回HTTP :: Response對象,該對象具有content方法。 打電話給那個。

$ua->request->content;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM