I find that the return from LWP::UserAgent->request()
contains both the header and body of a HTTP response. I just need the body of the response to do some parsing, so how can I
do?
views:
120answers:
2
+7
A:
The request
method (according to the manual) returns an HTTP::Response object, which has a content
method. Just call that.
$ua->request->content;
David Dorward
2009-12-17 08:57:28
You might actually want `decoded_content`, which deals with text encodings (in HTTP/MIME lingo, charsets) as well as HTTP `Content-Encoding`s like gzip.
hobbs
2009-12-17 11:41:08
+6
A:
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
will return the body of the response.
GJ
2009-12-17 09:17:31