Hi Jesper and Bill!

Well, the way suggested by you must do the job. But I was hoping that somebody 
was already implementing it in the 'get' method, side-by-side with the 
«':content_file' => $filename» and I somehow missed it. OK! I'll do it the hard 
way...

Thank you all
Meir

> -----Original Message-----
> From: Jesper Persson [mailto:jesper.j.pers...@gmail.com]
> Sent: Monday, April 16, 2012 7:36 AM
> To: Meir Guttman
> Cc: Libwww Perl
> Subject: Re: How to deflate a ':content_file' response saved to a file
> 
> 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 <m...@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
> >
> >
> 
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 9.0.929 / Virus Database: 271.1.1/4939 - Release Date:
> 04/15/12 21:34:00

Reply via email to