我是REST :: Client模块的新手。 我做了一个脚本,它将通过上面的模块调用API。
下面是我的剧本:
use REST::Client;
use Data::Dumper;
my $client = REST::Client->new();
my $resp = $client->request(
'POST',
"https://api.icims.com/customers/{ID}/search/people",
{
'Connection' => 'close',
'Link' => 'https://api.icims.com/customers/{ID}/people/;rel="person";
title="Person Profile"',
'Content-Length' => '280',
'Content-Type' => 'application/json',
'Content-Encoding' => 'gzip',
'Host' => 'api.icims.com',
'User-Agent' => 'Apache-HttpClient/4.2.1 (java 1.5)',
'Accept-Encoding' => 'gzip,deflate',
Accept => 'application/json'
}
);
print Dumper($resp->{_res}->{_content});
这是在响应下打印:
$VAR1 = '500 Not a SCALAR reference';
请建议。
答案 0 :(得分:0)
您错过了请求的正文。 A POST request with REST::Client应该首先是正文,然后是可选的标题。
POST($ url,[$ body_content,%$ headers])
对指定的资源执行HTTP POST。获取自定义请求标头的可选正文内容和hashref。
由于您似乎没有身体,只需使用undef
。
my $resp = $client->request(
'POST',
"https://api.icims.com/customers/{ID}/search/people",
undef, # here
{
'Connection' => 'close',
'Link' => 'https://api.icims.com/customers/{ID}/people/;rel="person";title="Person Profile"',
'Content-Length' => '280',
'Content-Type' => 'application/json',
'Content-Encoding' => 'gzip',
'Host' => 'api.icims.com',
'User-Agent' => 'Apache-HttpClient/4.2.1 (java 1.5)',
'Accept-Encoding' => 'gzip,deflate',
Accept => 'application/json'
}
);
使用POST
方法可能更好。它更容易阅读。
my $resp = $client->POST(
"https://api.icims.com/customers/ID/search/people",
undef,
{ ... }
);