in reply to Get a file with HTTP
The reason you aren't able to download a ZIP file with your code is this line:
$req->header(Accept => "text/html, */*;q=0.1");
This is malformed (see some documentation) in such a way that it is only letting you accept HTML documents. What you wanted to say was:
$req->header(Accept => "*/*; q=0.1, text/html");
Which means "I prefer HTML, I will take anything else if it is the best available after a 90% 'quality' hit".
Speaking HTTP is not easy, especially if you are just starting out. Unless you really need to speak HTTP directly like that, you should use one of the LWP kit's modules (which can use HTTP and FTP and the like automagically). I strongly agree with the people who have suggested LWP::Simple for the task you mention.
use LWP::Simple; #get ZIP file and store it locally as 'download.zip' getstore('http://localhost/testfile.zip', 'download.zip' ); #print HTML file to STDOUT my $content = get('http://localhost/dbconnect/instructions.htm'); if (defined $content) { # it worked! print $content,"\n"; } else { # there was a problem! warn 'Failed getting HTML file' }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Get a file with HTTP
by PugSA (Beadle) on Oct 27, 2005 at 11:36 UTC |