如何使用REST :: Client编写POST请求以在perl中生成令牌

时间:2014-08-19 05:45:41

标签: perl rest-client

我正在尝试为端口HTTP请求生成令牌。使用REST :: Client API进行POST请求是必要的。我使用下面的代码: -

#!/usr/bin/perl

 use strict;
 use warnings;
 use JSON;
 use REST::Client;

 my $client = REST::Client->new();
 $client->addHeader ('Accept' , 'application/json');
 my $request_url =  URL; #Instead of URL, in actual code i am passing correct URL.

$client->POST($request_url, '{ "auth": {"tenantName":"****", "passwordCredentials": {"username":"***","password":"****"} }}', { "Content-type" => 'application/json'}); #Instead of * i am sending actual values 

print $client->responseContent();
print "\n\n";
print $client->responseCode();
print "\n\n";

但我收到错误: -

{"error": {"message": "The resource could not be found.", "code": 404, "title": "Not Found"}}

404

我不知道为什么我会收到此错误。请有人帮我解决问题,或者是否有其他方法在perl中使用REST :: Client API发布请求?

0 个答案:

没有答案