So I’m pretty OK on adding forms to Curl requests in perl like so:
#!/usr/bin/perl
use WWW::Curl::Form;
use WWW::Curl::Easy;
sub chunk { my ($data,$pointer)=@_; ${$pointer}.=$data; return length($data) }
$i=WWW::Curl::Easy->new;
$w=$i->setopt(CURLOPT_URL,'https://url/path/');
$i->setopt(CURLOPT_WRITEFUNCTION, &chunk );
$i->setopt(CURLOPT_HEADERFUNCTION, &chunk );
$i->setopt(CURLOPT_WRITEHEADER, $headers );
$i->setopt(CURLOPT_FILE, $body );
my $form = WWW::Curl::Form->new();
$form->formadd('field','value');
$i->setopt( CURLOPT_HTTPPOST(), $form );
my $retcode=$i->perform();
But now I want to reuse the connection to post some JSON. Which means I need to clear the form from the request (I’m assuming since I also have the clear the headers and body). What is the correct way to do this? I can’t setopt the CURLOPT_HTTPPOST to null because no null and 0 doesn’t work either.