LWP HTTP request corrupted file

A

Ang Talunin

Hey,

I'm trying to create a perl script to download a zip file from a
website.
This is my code to download the file:

my $ua = new LWP::UserAgent;
my $reg = new HTTP::Request 'GET',"http://www.site.com/file.zip";
my $result = $ua->request($reg);
$html = $result->content if $result->is_success;
open OUT, ">file.zip" || die "Cannot write to outputfile";
print OUT $html;
close OUT;

But the stored zipfile is corrupted....
So I think that there's something wrong with the way I pass the file
from the HTTP request to the file, but can't find the right
solution....

Does anybody knows how to do this without corrupting the file? Thanx!

A.T.
 
G

Gregory Toomey

Ang said:
Hey,

I'm trying to create a perl script to download a zip file from a
website.
This is my code to download the file:

my $ua = new LWP::UserAgent;
my $reg = new HTTP::Request 'GET',"http://www.site.com/file.zip";
my $result = $ua->request($reg);
$html = $result->content if $result->is_success;
open OUT, ">file.zip" || die "Cannot write to outputfile";
Maybe you need:
binmode(OUT)
print OUT $html;
close OUT;

gtoomey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top