in reply to HTTP::Request::Common output format.

# Piece of pie; easy as cake :P my $post = POST ... print $post->as_string, $/;

Replies are listed 'Best First'.
Re^2: HTTP::Request::Common output format.
by KSHYAMKUMAR (Acolyte) on Apr 14, 2016 at 20:59 UTC

    Thanks. Could you suggest how to achive this using REST::Client POST request as well?

    use strict; use warnings; use REST::Client; use Data::Dumper; my $server = '...'; my $port = '...'; my $path = '/cdx/abc/gsa/deliverables'; my $application_id = '...'; my $application_password = '...'; my $host = 'localhost'; my %fields = ( deliverable_file => ["$ENV{PWD}/sample.xml"], data_transaction_code => "SOA", file_name => "RRR-xxxxxxxxxx.mmddyyyy-hhmmss.ext", agency_task_order_parameter => "12345667890", contractor_service_request_number => "123456780123456789" , deliverable_type => "Notification", data_transaction_file_date => "2016-01-21", tags => ["tagSample1", "tagSample2"] ); my $url = "http://$host:$port/cdx/abc/gsa/deliverables"; #print Dumper(\@INC) . "\n"; my $client = REST::Client->new(); # add the headers '-H' lines $client->addHeader('ABC_APP_ID', $application_id); $client->addHeader('IABC_APP_PASSWORD', $application_password); $client->addHeader('Content-Type', 'form-data' ); # add the fields '-F' lines print( $client->buildQuery(%fields)); $client->POST($url);

      And if you are planning to use that in more than one or two places, I'd monkey patch it so it's easier to maintain, and maybe submit a patch to the author–

      use REST::Client; sub REST::Client::response { +shift->{_res} } my $uri = "..."; my $client = REST::Client->new(); # ...some setup... print $client->POST($uri) ->response ->request ->as_string;

      Update, shortened call to what is available by removing the ->request

      Update to update, lengthened call to what was there before because it was right. :P

      The module doesn't afford what you want but it's in there if you dig it out.

      # Ewwwwwwwwwwww... print $client->{_res}->request->as_string, $/;

        hmm, getting the below error ... Can't locate object method "as_string" via package "REST::Client" at rest_client.pl line 35. sorry i sent the above message a bit too early...

        i am getting the below values in the output, does it send the request body only if the POST is successful?? I only could see the header in the output at the moment.

        REST::Client=HASH(0x2615438)POST http://localhost:.../cdx/abc/gsa/deli +verables User-Agent: REST::Client/273 Content-Length: 0 Content-Type: form-data ABC-APP-ID: ... IABC-APP-PASSWORD: ...