Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: how to post an xml using REST::Client

by spazm (Monk)
on Apr 07, 2016 at 21:41 UTC ( [id://1159846]=note: print w/replies, xml ) Need Help??


in reply to how to post an xml using REST::Client

Note, you'll want to learn the <code> tag when posting code on perlmonks.

So you want to translate this curl command into Rest::Client code, right?

curl -X POST \ -H "Content-Type: multipart/form-data" \ -H "ABC_APP_ID: <Application_ID>" \ -H "IABC_APP_PASSWORD: <Application_Password>" \ -F "deliverable_file=@sample.xml" \ -F "data_transaction_code=SOA" \ -F "file_name=RRR-xxxxxxxxxx.mmddyyyy-hhmmss.ext" \ -F "agency_task_order_parameter=12345667890" \ -F "contractor_service_request_number=123456780123456789" \ -F "deliverable_type=Notification" \ -F "data_transaction_file_date=2016-01-21" \ -F "tags=\"tagSample1\", \"tagSample2\"" \ "http://<server>:<port>/cdx/abc/gsa/deliverables"
should look something like:
#!/usr/bin/perl use strict; use warnings; use REST::Client; my $server = 'localhost'; my $port = '7999'; my $path = '/cdx/abc/gsa/deliverables'; my $application_id = '...'; my $application_password = '...'; my %fields = ( deliverable_file => "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://$server:$port/cdx/abc/gsa/deliverables"; my $client = REST::Client->new({host => $url}); # add the headers '-H' lines $client->addHeader('ABC_APP_ID', $application_id); $client->addHeader('IABC_APP_PASSWORD', $application_password); # add the fields '-F' lines my $get_query = $client->buildQuery(%fields); #this doesn't help for +POST $client->POST($url);
Note: edited to remove the major code errors

Replies are listed 'Best First'.
Re^2: how to post an xml using REST::Client
by KSHYAMKUMAR (Acolyte) on Apr 07, 2016 at 21:53 UTC

    Thanks for the tip on <code> tag. i am fairly new to the perl monks. You are correct i would need to translate the curl command into REST::Client code.

Re^2: how to post an xml using REST::Client
by 1nickt (Canon) on Apr 08, 2016 at 19:53 UTC

    my %fields = ( deliverable_file => "@sample.xml",
    This will attempt to interpolate the string since it is in double quotes. If you really have a file called @sample.xml (which seems like an unfortunate choice of filename), you should quote it with single quotes so Perl doesn't try to replace @sample with the contents of a non-existent array.

    Other errors with this code:

    $ perl -c 1159843.pl Possible unintended interpolation of @sample in string at 1159843.pl l +ine 11. Global symbol "@sample" requires explicit package name at 1159843.pl l +ine 11. Global symbol "$host" requires explicit package name at 1159843.pl lin +e 21. Bareword "tags" not allowed while "strict subs" in use at 1159843.pl l +ine 10. 1159843.pl had compilation errors.

    Hope this helps!


    The way forward always starts with a minimal test.

      Hi 1nickt,

      My filename is sample.xml, since the curl command has downloadable_file as @sample.xml, it was formatted like that by the previous Perl monks user who responded to my post. if i specify the downloadable_file => 'sample.xml', does it transfer the file RESTfully to the destination.

        I can't tell if your last sentence is a statement or a question, but either way you should begin with a *new* simple script that attempts to use the module you have chosen, to do its most simple task. Forget all about your data and just try to write a script that will POST a very simplified, generic request to a server. Then go from there.


        The way forward always starts with a minimal test.
Re^2: how to post an xml using REST::Client
by KSHYAMKUMAR (Acolyte) on Apr 07, 2016 at 21:57 UTC

    Thank you very much for the quick reply. I will give it a try and get back to you. one question on deliverablefile, So it takes the file from current directory and transfers it over to http://$host:$port/cdx/abc/gsa/deliverables ??

        Hi spazm. Thank you for the responses. i tried to go through the modules you have specified, but without much luck. May i request you to kindly help me update the below code you have provided to send the xml(sample.xml)??

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1159846]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-20 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found