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

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);

Replies are listed 'Best First'.
Re^3: HTTP::Request::Common output format.
by Your Mother (Archbishop) on Apr 14, 2016 at 21:50 UTC

    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

Re^3: HTTP::Request::Common output format.
by Your Mother (Archbishop) on Apr 14, 2016 at 21:32 UTC

    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: ...

        You cannot get that error from the code I offered.

        I haven’t played with REST::Client or used it and I wouldn’t. It’s the wrong candidate, in my view, for this kind of chained method stuff, its error handling is not ideal, and if you examine the source you’ll see that everything it’s doing is pretty straightforward while also being limited in arbitrary ways.

        I’ve written lots of mini-REST clients—usually for testing—using WWW::Mechanize + JSON + URI, and the HTTP:: family and that’s where I’d recommend looking. Although, in your case, since you’re using XML you may need XML::LibXML or XML::Twig or something. If the REST service can respond in JSON, I strongly recommend it over XML.