Perl WWW::Curl无法在帖子正文中附加WWW::Curl::表单数据
有人知道为什么下面的代码不会从请求主体中的WWW::Curl::Form对象发送POST数据吗Perl WWW::Curl无法在帖子正文中附加WWW::Curl::表单数据,perl,http,post,curl,Perl,Http,Post,Curl,有人知道为什么下面的代码不会从请求主体中的WWW::Curl::Form对象发送POST数据吗 #!/usr/bin/perl use strict; use warnings; use WWW::Curl::Easy; use WWW::Curl::Form; my $curl = new WWW::Curl::Easy(); $curl->setopt(CURLOPT_VERBOSE, 1); $curl->set
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Curl::Easy;
use WWW::Curl::Form;
my $curl = new WWW::Curl::Easy();
$curl->setopt(CURLOPT_VERBOSE, 1);
$curl->setopt(CURLOPT_NOSIGNAL, 1);
$curl->setopt(CURLOPT_HEADER, 1);
$curl->setopt(CURLOPT_TIMEOUT, 10);
$curl->setopt(CURLOPT_URL, 'http://localhost/post_test.php');
my $curlf = new WWW::Curl::Form();
$curlf->formadd('a','b');
$curlf->formadd('c','d');
$curlf->formadd('e','f');
$curlf->formadd('g','h');
$curlf->formadd('i','j');
$curl->setopt(CURLOPT_HTTPPOST, $curlf);
my $resp = '';
open(my $resp_fh, ">", \$resp);
$curl->setopt(CURLOPT_WRITEDATA, $resp_fh);
my $retcode = $curl->perform();
die($retcode) if ($retcode != 0);
print $resp;
这是我看到的POST请求(在详细输出和Wireshark中):
如您所见,没有内容类型,内容长度为0,正文中没有数据
这是在Debian上使用libcurl3 7.21.0-2和libwww curl perl 4.12-1实现的。尝试使用另一个包装器,:
尝试使用另一个包装器:
c示例可以很好地提交多部分/表单数据。这个库看起来很好,这可能是WWW::Curl包装器中的一个问题。该库看起来很好,这可能是WWW::Curl包装器中的一个问题。
POST /post_test.php HTTP/1.1
Host: localhost
Accept: */*
Content-Length: 0
#!/usr/bin/perl
use strict;
use warnings;
use Net::Curl::Easy qw(:constants);
use Net::Curl::Form qw(:constants);
my $curl = new Net::Curl::Easy();
$curl->setopt(CURLOPT_VERBOSE, 1);
$curl->setopt(CURLOPT_NOSIGNAL, 1);
$curl->setopt(CURLOPT_HEADER, 1);
$curl->setopt(CURLOPT_TIMEOUT, 10);
$curl->setopt(CURLOPT_URL, 'http://localhost/post_test.php');
my $curlf = new Net::Curl::Form();
$curlf->add(CURLFORM_COPYNAME ,=> 'a', CURLFORM_COPYCONTENTS ,=> 'b');
$curlf->add(CURLFORM_COPYNAME ,=> 'c', CURLFORM_COPYCONTENTS ,=> 'd');
$curlf->add(CURLFORM_COPYNAME ,=> 'e', CURLFORM_COPYCONTENTS ,=> 'f');
$curlf->add(CURLFORM_COPYNAME ,=> 'g', CURLFORM_COPYCONTENTS ,=> 'h');
$curlf->add(CURLFORM_COPYNAME ,=> 'i', CURLFORM_COPYCONTENTS ,=> 'j');
$curl->setopt(CURLOPT_HTTPPOST, $curlf);
my $resp = '';
open(my $resp_fh, ">", \$resp);
$curl->setopt(CURLOPT_WRITEDATA, $resp_fh);
my $retcode = $curl->perform();
die($retcode) if ($retcode != 0);
print $resp;