develooper Front page | perl.libwww | Postings from April 2012

Re: How to deflate a ':content_file' response saved to a file

Thread Previous | Thread Next
From:
Jesper Persson
Date:
April 15, 2012 21:36
Subject:
Re: How to deflate a ':content_file' response saved to a file
Message ID:
CA+uC3V0TZc7qQRkSx1VF2D1iQb_6J0s0guThiT6mcjY2pBd-sQ@mail.gmail.com
Hi Meir,

you can set the reponse content and then use decoded_content. Something
like this:

$response = $ua->request($request, $filename);

undef $/;
open(FH, "<$filename");
binmode(FH);
$pageContent = <FH>;
close (FH);
$/ = "\n";

$response->content($pageContent);
my $decoded_pagecontent = $response->decoded_content( raise_error => 1);

Regards,
Jesper

On 14 April 2012 22:25, Meir Guttman <meir@guttman.co.il> wrote:

> I would like to download gzip (or similarly encoded) HTML content. If I
> keep the response in a variable, I can decode the contents using the
> 'decoded_content' method, as follows (Just extracted from a working
> script, but not tested):
>
> ####################################
>        use strict;
>        use warnings;
>        use base 'HTTP::Message';
>        use LWP::UserAgent
>
>        my $can_accept = HTTP::Message::decodable;
>
>        my $ua = LWP::UserAgent->new;
>        my $response = $ua->get($uri, 'Accept-Encoding' => $can_accept);
>        print $response->decoded_content, "\n";
> ####################################
>
> On the other hand, another variation of the 'get' method can save a
> response to a file, as in:
>
>        $ua->get($url, ':content_file' => $filename);
>
> But I couldn't find a way to first deflate the contents that is
> saved to file.
>
> Can someone point me to the right part of the LWP package?
>
> Thanks,
> Meir
>
>


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About