When hard coding (tid,name) in the $content variable, I will able to pass the request successfully using LWP::UserAgent perl module whereas it doesn't working fine while invoking the POST method by passing the content with a string value (tid,name) in the hash array is throwing the 500 Internal Server Error.
#! /usr/local/bin/perl
use LWP::UserAgent;
use JSON;
#Variable declaration
my $tk = 123456;
my $tid = 1234;
my $name = "Mark";
my $url = "https://xxx/vs/v2/api/instance";
#HTTP Content
my $content =qq{
{
"application.name": "NBM",
"application.version": "1.1",
"envvars":
[
{
"id": "KEY1/m_1.1",
"value": "
{
"a_a_i":
{
"c_id_value":"APP",
"selection_type":"user",
"c_id_doc_v ":"1.0",
"c":"sm",
"c_id":"sm","c_id":13
},
"c_a_i":
[
{
"c_id_vue":"APP",
"customer_identifier":"account_id",
"customer_type":"unknown",
"licensing_model":"unknown",
"entitlement":
[
{
"entitlement_id":"id",
"quantity":290
}
]
},
{
"customer_identifier_value":"APP",
"customer_identifier":"account_id",
"customer_type":"unknown",
"licensing_model":"unknown",
"entitlement":
[
{
"entitlement_id":"id",
"quantity":290
}
]
},
{
"customer_identifier_value":"P",
"customer_identifier":"account_id",
"customer_type":"unknown",
"licensing_model":"unknown",
"entitlement":
[
{
"entitlement_id":"id",
"quantity":259
}
]
}
]
}
},
{
"id": "KEY2/m_1.1",
"value": ""
},
{
"id": "KEY3/m_1.1",
"value": "0"
}
],
"network":
[
{
"id": "hname/m_1.1",
"value": "xxx.y.z.com"
},
{
"id": "I/m_1.1",
"value": "$name"
},
{
"id": "ipaddress/m_1.1",
"value": "10.20.33.xx"
},
{
"id": "t/m_1.1",
"value": "$tid"
},
{
"id": "domainname/m_1.1",
"value": "y.z.com"
},
{
"id": "nameservers/m_1.1",
"value": "17x.34.5.6"
},
{
"id": "sd/m_1.1",
"value": "y.z.com"
},
{
"id": "etc/m_1.1",
"value": ""
}
],
"volume":
[
{
"id": "ctb/m_1.1",
"value": "25GB"
}
]
}
};
my $ua =LWP::UserAgent->new(
ssl_opts => { verify_hostname => 0 });
#POST Method with headers
my $req = HTTP::Request->new('POST' => $url);
$req->header ('Content-Type'=>'application/json');
$req->header('X-Auth-Token'=>$tk);
$req->header('Accept'=>'*/*');
$req->header('Accept-Encoding'=>'gzip, deflate, br');
$req->header('Connection'=>'keep-alive');
$req->content($content);
my $res = $ua->request($req);
print $res->as_string;
#Checking Response
if($res->is_success)
{
print $res->content, "\n";
}
else
{
print $res->status_line, "\n";
}