开发者

Undefined subroutine error using WWW::Curl::Form in Perl

开发者 https://www.devze.com 2023-02-03 05:22 出处:网络
I have this error in my script, but everything seems to be in order: Undefined subroutine &WWW::Curl::Form::curl_formaddfile caclled at /home/script.pm line 107

I have this error in my script, but everything seems to be in order:

Undefined subroutine &WWW::Curl::Form::curl_formaddfile caclled at /home/script.pm line 107

lines around 107 line looks like this:

my $curlf = WWW::Curl::Form->new;

$curlf->curl_formaddfile($nfo, 'nfo', "multipart/form-data"); #107 line
$curlf->curl_formaddfile($torrent, 'file', "multipart/form-data");
$curlf->curl_forma开发者_如何学Pythondd("name", $name);
$curlf->curl_formadd("type", $category);
$curlf->curl_formadd("descr", $$descr_txt);
$curlf->curl_formadd("anonymous", "1");
$curlf->curl_formadd("samehash", "1");

my $curl = new WWW::Curl::Easy;
my $response_details;
# windows check
if($os eq "windows"){
    $curl->setopt(CURLOPT_WRITEFUNCTION, \&curl_write_data); 
}else{
    open (my $response_details_raw, ">", \$response_details);
    $curl->setopt(CURLOPT_WRITEDATA,$response_details_raw);
}
my @curl_headers=('Expect:');
$curl->setopt(CURLOPT_HTTPHEADER, \@curl_headers);
$curl->setopt(CURLOPT_FOLLOWLOCATION, 1);
$curl->setopt(CURLOPT_RETURNTRANSFER, 1);
$curl->setopt(CURLOPT_SSL_VERIFYPEER, 1);
$curl->setopt(CURLOPT_SSL_VERIFYHOST, 1);
$curl->setopt(CURLOPT_TIMEOUT, 60);
$curl->setopt(CURLOPT_VERBOSE, 0);
$curl->setopt(CURLOPT_COOKIE, $cookie_glabella);
$curl->setopt(CURLOPT_REFERER, $upload_referer);
$curl->setopt(CURLOPT_HTTPPOST, $curlf);

$nfo prints out as /home/file.nfo

after that goes WWW::Curl::Easy and it does not work as it can not POST from this data. What could be the problem?


For the doc, the method curl_formaddfile is listed in the Compatibility section (Seems to be working.). Maybe you have a newer module so you should use the method formaddfile instead

See below an example from the doc:

    use WWW::Curl::Form;
    my $curlf = WWW::Curl::Form->new;
    $curlf->formaddfile($filename, 'attachment', "multipart/form-data");
    $curlf->formadd("FIELDNAME", "VALUE");

    $curl->setopt(CURLOPT_HTTPPOST, $curlf);
0

精彩评论

暂无评论...
验证码 换一张
取 消