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"; }
The output:
ERROR:: HTTP/1.1 500 Internal Server Error Connection: close Date: Sun, 12 Apr 2020 07:13:47 GMT Server: nginx/1.12.2 Content-Length: 78 Content-Type: text/plain; charset=utf-8a Client-Date: Sun, 12 Apr 2020 07:13:47 GMT Client-Peer: 10.32.45.x:443 Client-Response-Num: 1 Client-SSL-Cert-Issuer: /C=US/ST=xxxx/O=xxx/OU=rrr/CN=x.y.z.com-in +term2000000000000 Client-SSL-Cert-Subject: /C=US/ST=Cxxxxxx/L=cdlf view/O=********/O +U=XXXXXXX/CN=cons Client-SSL-Cipher: ZBAJSD-SBSHHS-HSJDD-**** Client-SSL-Socket-Class: IO::Socket::SSL Client-SSL-Warning: Peer certificate not verified X-Content-Type-Options: noDFDFD {"errorCode”:”XX-XX-XXX”,”errorMessage":"Internal server error occ +urred"}
2020-04-13 Athanasius added readmore tags to main code and code tags to error output.
In reply to Getting 500 Internal Error while calling POST method by passing content in PERL script by sathis4mailing
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |