in reply to Bad Request 4000: HTTP::Request->new(POST => $server_endpoint)

As jmacloue points out, it looks like you are trying to send JSON data, and the $post_data is not valid JSON, and you are not setting the content-type. I find it is often easier to create the data as a normal Perl structure and then use the JSON module to encode it:
use LWP::UserAgent; use JSON; my $ua = LWP::UserAgent->new; my $server_endpoint = "http://api.someserver.com/v1/"; my $req = HTTP::Request->new(POST => $server_endpoint); $req->authorization_basic('myusername', 'mypassword'); my $post_data = { parm1 => $valueasscalar, parm2 => \1, # this gives you a proper JSON 'true' }; my $json = encode_json($post_data); $req->content_type('application/json'); $req->content($json); my $resp = $ua->request($req); # etc
  • Comment on Re: Bad Request 4000: HTTP::Request->new(POST => $server_endpoint)
  • Download Code

Replies are listed 'Best First'.
Re^2: Bad Request 4000: HTTP::Request->new(POST => $server_endpoint)
by Trace On (Novice) on Apr 16, 2015 at 07:30 UTC
    Right! The request was rubbish. The curl-hint did half of the job: Helped debugging! The other half was switching to json! Thank you!