Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Getting 500 Internal Error while calling POST method by passing content in PERL script

by sathis4mailing (Initiate)
on Apr 13, 2020 at 00:43 UTC ( [id://11115409]=perlquestion: print w/replies, xml ) Need Help??

sathis4mailing has asked for the wisdom of the Perl Monks concerning the following question:

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.

  • Comment on Getting 500 Internal Error while calling POST method by passing content in PERL script
  • Select or Download Code

Replies are listed 'Best First'.
Re: Getting 500 Internal Error while calling POST method by passing content in PERL script
by marto (Cardinal) on Apr 13, 2020 at 07:50 UTC

    You don't say what API/Service you are communicating with, and the error is being returned by this service. You'd need to check their API documentation or contact them if you are having problems. As it stands nobody will be able to help you with this, too many unknowns.

      Marto , Thanks for your response. The following REST API "https://*************/instance" is working fine in the POSTMAN. I am facing issue while executing through the perl code and not sure what is wrong in the code.
Re: Getting 500 Internal Error while calling POST method by passing content in PERL script
by jo37 (Deacon) on Apr 13, 2020 at 08:46 UTC

    Just a wild guess: Remove the quotes around "$tid"

    Greetings,
    -jo

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$
      Jo , Thanks. I tired.. still issue persists.

        Post the version that is working then.

        Greetings,
        -jo

        $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11115409]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-20 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found