The POD shows the content and headers wrapped in an anonymous array. Does that work?

$client->POST ('https://api.sixfold.com/v1/companies/296/carrier-shipm +ents/0005360404/allocation', [ '{"type":"vehicle", "vehicle_id":"39257" +}', {Authorization => 'Bearer 096dd6e084d5f30fazzz', "Content-type" => + 'application/json'} ] );

REST::Client

=head3 POST ( $url, [$body_content, %$headers] ) Preform an HTTP POST to the resource specified. Takes an optional body + content and hashref of custom request headers. =cut

Nope thats just indicating optional arguments, sorry.

There's some faffing with checking if the content is a scalar ref, maybe something to do with that?

update The content appears to be getting set from REST::Client. It's not passed in on the new so it is not set at construction time. Although the variable $http_req{_content} is set to the empty string at this time, so it exists.

The subroutine then queries if wantarray is defined. Although I don't think it is, if it is it will set the content and return the empty string. If not defined it will just set the content. If it is being called in void context it should Carp on global warnings being set so you'd be aware of that, also that would have been flagged before now I'm sure. Then it returns.

The set_content routine does a utf8_downgrade, but I don't think there are any problematic characters in that string. Then sets the string as the content.

Then it moves on to setting the headers and custom_headers, but you already said its not the headers.

So I can't see anything from reading through that would be a problem as such.

Aside from that, I was not sure exactly how the lc function in the auto getter/setter is working, and might ask someone to look at that for a second opinion.

update 2:From this point I could suggest sending a POST request from HTTP::Request directly and comparing the results, working back from there. HTTP::Request provides a dump routine, but its not documented so use at own risk.

#HTTP::Request POD =head2 Simple POST Here, we'll create a simple POST request that could be used to send JS +ON data to an endpoint. #!/usr/bin/env perl use strict; use warnings; use Encode qw(encode_utf8); use HTTP::Request (); use JSON::MaybeXS qw(encode_json); my $url = 'https://www.example.com/api/user/123'; my $header = ['Content-Type' => 'application/json; charset=UTF-8'] +; my $data = {foo => 'bar', baz => 'quux'}; my $encoded_data = encode_utf8(encode_json($data)); my $r = HTTP::Request->new('POST', $url, $header, $encoded_data); # at this point, we could send it via LWP::UserAgent # my $ua = LWP::UserAgent->new(); # my $res = $ua->request($r); =cut

Maybe that can help you back engineer into the REST::Client framework to get the response you are after. Formatting the data using the encode routines suggested in the pod could be a good start.


In reply to Re: REST::Client POST help by Don Coyote
in thread REST::Client POST help by ogrp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.