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

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

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

    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.

      may i request you for a sample code to send an xml with header and body content over to a REST server ??

      my requirement is to convert the below curl command into a REST webservice call to transfer sample.xml to the server.

      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"

        Oh, ok! Fine!!! Your problem is more interesting than those in my bag of holding. You will really need to dig into the documentation to make this fun and easy: HTTP::Request, LWP::UserAgent, WWW::Mechanize, &c. :P

        #!/usr/bin/env perl use strictures; use WWW::Mechanize; use URI; use HTTP::Request::Common; # For fun/test, see comment below. my $app_id = shift || $ENV{APPLICATION_ID} || die "Give or set APPLICA +TION_ID\n"; my $app_pass = shift || $ENV{APPLICATION_PASS} || die "Give or set APP +LICATION_PASS\n"; my $dingus = WWW::Mechanize->new( autocheck => 0, agent => "MelleMelBot/1.0" ); $dingus->default_header( ABC_APP_ID => $app_id, IABC_APP_PASSWORD => $app_pass ); my $uri = URI->new("http://<server>:<port>/cdx/abc/gsa/deliverables"); my $post = POST $uri, Content_Type => "form-data", Content => [ deliverable_file => [ "real-path-to-sample.xml" ], file_name => "RRR-xxxxxxxxxx.mmddyyyy-hhmmss.ext", agency_task_order_parameter => "12345667890", contractor_service_request_number => "123456780123456 +789", deliverable_type => "Notification", data_transaction_file_date => "2016-01-21", tags => "[tagSample1, tagSample2]" ]; # Peek if you will. Note, default headers are not there yet. # print $post->as_string; my $response = $dingus->request( $post ); # $post object is just demo intermediary. # This could also be $dingus->post( $uri, Content ... ); # Default headers are there because they went through the Mech object. print $response->request->as_string;

        What code have you already written using WWW::Mechanize and where does your code not work?

        I might be able to help you out here but first I'd like to know if the REST service has public facing documentation I could see? If not, does it also speak JSON / could you provide a JSON example request?