Using WWW::Curl::Easy with Perl

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Does anyone in here have a good working knowledge of using the
WWW::Curl::Easy module with Perl? Basically, my problem is that I have
been trying to download a file using the WWW::Curl::Easy module without
any success, in a Perl cgi-bin.

For some reason, it is not putting the requested data into a file,
instead I get it printed on the page itself.

Any ideas why?

---cut here---

use WWW::Curl::Easy;
use CGI;

use strict;

my $cgi = new CGI;

print $cgi->header;
print $cgi->start_html("downloader");

my $file = "temp/" . $$ . "sitemap.gz";
my $url = " ";

my $curl = WWW::Curl::Easy->new;

print $cgi->p("[" . $url . "][" . $file . "]");

$curl->setopt(CURLOPT_URL, $url);
$curl->setopt(CURLOPT_TIMEOUT, 120);
$curl->setopt(CURLOPT_REFERER, "Fubra_Sitemap_Validator");
$curl->setopt(CURLOPT_WRITEDATA, 0);

open SITEMAP, "> $file";
$curl->setopt(CURLOPT_FILE, *SITEMAP);

my $return_code = $curl->perform;
my $response_code = $curl->getinfo(CURLINFO_HTTP_CODE);

print $cgi->p("DEBUG [" . $response_code . "][" . $return_code . "]");
print $cgi->p($curl->strerror($return_code));

if ($response_code <= 400 && $return_code == 0)
        print $cgi->p("success");

close SITEMAP;
---cut here---

Re: Using WWW::Curl::Easy with Perl

On Mon, 21 Jul 2008 16:15:56 +0100

As a follow-up:

Quoted text here. Click to load it

That should have been:

$curl->setopt(CURLOPT_FILE, \*SITEMAP);

Why this wasn't made clear in the WWW::Curl::Easy, I'll never know...


Site Timeline