我曾嘗試下面的代碼如何使用LWP :: UserAgent在BOX API中發佈發佈請求?
my $url = "https://api.box.com/2.0/users/";
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request::Common qw{ POST };
use CGI;
my $ua = LWP::UserAgent->new();
my $request = POST($url, [ 'name' => 'mkhun', 'is_platform_access_only' => 'true',"Authorization" => "Bearer <ACC TOK>" ]);
my $content = $ua->request($request)->as_string();
my $cgi = CGI->new();
print $cgi->header(), $content;
上面的代碼總是給出400錯誤。並投擲
{"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"invalid_parameter","name":"entity-body","message":"Invalid value 'is_platform_access_only=true&Authorization=Bearer+WcpZasitJWVDQ87Vs1OB9dQedRVyOrs6&name=mkhun'. Entity body should be a correctly nested resource attribute name\/value pair"}]},
我不知道是什麼問題。 Linux curl也一樣。
curl https://api.box.com/2.0/users \
-H "Authorization: Bearer <TOKEN>" \
-d '{"name": "Ned Stark", "is_platform_access_only": true}' \
-X POST
TRUE;和''true''並不意味着同樣的事情。 ''和'{...}'是不可互換的。 –
@SinanÜnür''''和'{''}'在用LWP發佈表單數據時大多可以互換。 – melpomene
@melpomene您假設接收方的軟件不關心參數指定的順序。不太可能,當然,但不是不可想象的。 –