Trace On has asked for the wisdom of the Perl Monks concerning the following question:
Ok. I give up. Hundreds of code lines working. Solved most of my issues by reading and reading and reading. Retrieved lots of data, stored it, did fancy things with it...
... and finally ... I got stuck. And finally I have to switch from passive perl monks support to active support.
So, deardear Monks, what - generally speaking - is wrong with my code (credit: not my code, copypasted from somewhere)?:
To be more specific: The error messages are:my $ua = LWP::UserAgent->new; my $server_endpoint = "https://api.someserver.com/v1/"; my $req = HTTP::Request->new(POST => $server_endpoint); $req->authorization_basic('myusername', 'mypassword'); my $post_data = "{ 'parm1': '$valueasscalar', 'parm2': 'TRUE',and: + 'so on'}"; $req->content($post_data); my $resp = $ua->request($req); if ($resp->is_success) { my $message = $resp->decoded_content; print "Received reply: $message"; } else { print "HTTP POST error code: ", $resp->code; print "HTTP POST error message: ", $resp->message; }
HTTP POST error code: 400 HTTP POST error message: Bad Request
Is there something wrong with my code? Or is the code ok, but something wrong with the parameters?
All help is as appreciated as ever when reading on perlmonks!
Thanks, Trace on
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bad Request 4000: HTTP::Request->new(POST => $server_endpoint)
by jmacloue (Beadle) on Mar 16, 2015 at 10:39 UTC | |
|
Re: Bad Request 4000: HTTP::Request->new(POST => $server_endpoint)
by tangent (Parson) on Mar 16, 2015 at 14:56 UTC | |
by Trace On (Novice) on Apr 16, 2015 at 07:30 UTC | |
|
Re: Bad Request 4000: HTTP::Request->new(POST => $server_endpoint)
by Anonymous Monk on Mar 16, 2015 at 09:29 UTC |