cURL / Mailing Lists / curl-library / Single Mail

curl-library

setopt(CURLOPT_*,$curlopthash->{$option}) apparently doesn't work

From: Wurtz, Frederick (GE, Research, consultant) <wurtz_at_ge.com>
Date: Wed, 8 Oct 2008 12:08:59 -0400

Hello. After setting up a hash thusly

%curlopthash = (
                        CURLOPT_URL => $url,
                        CURLOPT_PROXY => "",
                .
                .
                .
                CURLOPT_FOLLOWLOCATIOIN => 1
                );

..and then passing a reference to that hash to a method like "sub curl"
below ....

sub curl {
         my $curlopthash=shift;
         my $curl = new WWW::Curl::Easy;

         foreach my $option (keys(%$curlopthash)) {
        $curl->setopt($option,$curlopthash->{$option});
         }

         .
         .
         $my return_code = $curl->perform;

         .
         .
}

...it appears that the name/value pairs delivered to the method via the
hash reference do not correctly get assigned via the $curl->setopt
calls.

I've verified that $option is, in each case the correct "CURLOPT_*"
string and that $curlopthash->{$option} contains the correct values, but
unless I scrap this in favor of localized, "static" assignments like ..

$curl->setopt(CURLOPT_URL,$url) ...etc, right in the "curl" method, the
$curl->perform fails, as verifed with error checking code like

unless ($returncode == 0) {
        print "ERROR: ".$curl->strerror($return_code)."
($return_code)\n";
}

Also, as further verifiaction of failure, the expected response header
value is not returned, and in fact is blank. The error message from the
$curl->strerr is "ERROR: URL using bad/illegal format or missing URL
(3)", and I've proven that doing the CURLOPT_URL assignment locally
produces a further degree of success, and by doing all of the
assignments locally as depicted above, the whole thing works as
expected.

Does somone have an idea why I would have to hard code the
$curl-setopt(CURLOPT_*, <value>) calls locally, even when the passed-in
hash is providing the same values?

Thanks for the help.
Fred Wurtz
Received on 2008-10-08