perl curl代码等效于-d -u

时间:2017-10-27 04:42:20

标签: perl curl

如何在命令提示符下卷曲下面的卷曲代码在perl WWW中表示:卷曲?

curl https://api.stripe.com/v1/charges \
   -u sk_test_a02zSeLS9cMPlJvu2GkWgSDB: \
   -d amount=1000 \
   -d currency=sgd \
   -d description="Example charge" \
   -d source=tok_2s0QJK6exWUdbSGZb4SpAKep

perl的

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

$curl->setopt(CURLOPT_HEADER,1);
$curl->setopt(CURLOPT_URL, 'https://api.stripe.com/v1/charges');

# A filehandle, reference to a scalar or reference to a typeglob can be used here.
my $response_body;
$curl->setopt(CURLOPT_WRITEDATA,\$response_body);

# Starts the actual request
my $retcode = $curl->perform;

1 个答案:

答案 0 :(得分:0)

正如您在示例中所看到的here

use WWW::Curl::Form;
my $curlf = WWW::Curl::Form->new;
$curlf->formadd("amount", "1000");
$curlf->formadd("currency", "sgd");
$curlf->formadd("description", "Example charge");
$curlf->formadd("source", "tok_2s0QJK6exWUdbSGZb4SpAKep");
$curl->setopt(CURLOPT_HTTPPOST, $curlf);
$curl->setopt(CURLOPT_USERPWD,"sk_test_a02zSeLS9cMPlJvu2GkWgSDB:");