Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

HTTP::Request::Common output format.

by KSHYAMKUMAR (Acolyte)
on Apr 14, 2016 at 20:13 UTC ( [id://1160464]=perlquestion: print w/replies, xml ) Need Help??

KSHYAMKUMAR has asked for the wisdom of the Perl Monks concerning the following question:

while going through the HTTP::Request::Common module in cpan http://search.cpan.org/~ether/HTTP-Message-6.11/lib/HTTP/Request/Common.pm i came across the below output for some scripts. Could someone guide me on how to see the output in the format provided in the page ??

Code

POST 'http://www.perl.org/survey.cgi', Content_Type => 'form-data', Content => [ name => 'Gisle Aas', email => 'gisle@aas.no', gender => 'M', born => '1964', init => ["$ENV{HOME}/.profile"], ]

Output

POST http://www.perl.org/survey.cgi Content-Length: 388 Content-Type: multipart/form-data; boundary="6G+f" --6G+f Content-Disposition: form-data; name="name" Gisle Aas --6G+f Content-Disposition: form-data; name="email" gisle@aas.no --6G+f Content-Disposition: form-data; name="gender"

Replies are listed 'Best First'.
Re: HTTP::Request::Common output format.
by Your Mother (Archbishop) on Apr 14, 2016 at 20:20 UTC
    # Piece of pie; easy as cake :P my $post = POST ... print $post->as_string, $/;

      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, $/;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1160464]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2024-04-23 14:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found