Hello,
I'm trying to consume a web service using Perl. If I use a browser to access the service, the results are returned as formatted XML. This is the response result I'm looking for so that I can subsequently process the results as XML.
I have been able to return results using the LWP::Simple module. However, the results come back in a form that is similar to nested hashes (resembling the compact version of the Dumper module output) see below:
Data Returned:
[{"Header":{"VendorIdNumber":22349.0,"VendorName":"Some Business","Location":"01","ShipDate":"05-JUL-2016","ShipTime":"00:00:00 AM","TruckNumber":"201607051359FON "},"Items":[{"PONumber":"1343987-K ","POLineNumber":0.0,"SONumber":220759.0,"SOLineNumber":6.0,"QuantityShipped":80.0,"RackNumber":3127824.0},{"PONumber":"1343987-K ","POLineNumber":0.0,"SONumber":220759.0,"SOLineNumber":1.0,"QuantityShipped":196.0,"RackNumber":3127825.0}]},{"Header":{"VendorIdNumber":22349.0,"VendorName":"Some Business","Location":"01","ShipDate":"07-JUL-2016","ShipTime":"00:00:00 AM","TruckNumber":"201607071414FON "},"Items":[{"PONumber":"1343987-K ","POLineNumber":0.0,"SONumber":220759.0,"SOLineNumber":2.0,"QuantityShipped":132.0,"RackNumber":3127828.0},{"PONumber":"1343987-K ","POLineNumber":0.0,"SONumber":220759.0,"SOLineNumber":3.0,"QuantityShipped":135.0,"RackNumber":3128353.0},{"PONumber":"1343987-K ","POLineNumber":0.0,"SONumber":220759.0,"SOLineNumber":5.0,"QuantityShipped":2.0,"RackNumber":3128796.0},{"PONumber":"1343987-K ","POLineNumber":0.0,"SONumber":220759.0,"SOLineNumber":6.0,"QuantityShipped":2.0,"RackNumber":3128797.0}]}]
Here is the code used to retrieve the above data
use LWP::UserAgent;
use HTTP::Request::Common qw(GET);
my $ua = LWP::UserAgent->new;
my $endpoint = 'http://www.SomeBusiness.com:8081/api/CustomerDir/getA
+SN';
my $req = HTTP::Request->new('GET');
$req->url($endpoint);
my $resp = $ua->request($req);
my $message = $resp->content;
print "printing message: $message\n\n";
If I just take the $endpoint URL and access it using Firefox, I get formatted XML returned.
I have also tried using SOAP::Lite to access the web service, but SOAP must pass a POST call somewhere in the pre-process set up and this web service won't allow a POST method.
Can someone tell me what I need to add or which module I need to use so that I can do with Perl, programmatically, what my browser does automatically, i.e. it knows to automatically format the returned data as XML or knows that is should not be formatted as nested hashes when returned?
Thanks,
pkupnorth
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.