homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

Calling a Web Service from Perl
How to call a Web Service from Perl that returns XML

 1:38 pm on Apr 18, 2007 (gmt 0)

I'm trying to figure out how to call a web service (REST type) from a CGI Perl file. The web service returns XML so I would also need to know the best way to pull data out of the returned XML.

The call to the web service would be a URL call like:

Any ideas?



 5:05 pm on Apr 18, 2007 (gmt 0)

I was actually messing with this today, Yahoo have an SDK that includes PERL that does exactly that, queries using REST and returns XML.

Wasn't Yahoo you were doing was it?

It's on [developer.yahoo.com...] somewhere but the site seems to be down at the moment.


 7:20 pm on Apr 18, 2007 (gmt 0)

Many don't like it because it's slow (although most of my requests are semi-instantaneous,) but I've never had any problem with XML::Simple. Easy to install too, doesn't need to be cpann'ed (but that's best.)


 10:48 am on Apr 19, 2007 (gmt 0)

if you are asking about how to HTTP GET the document in a perl way you could use something like:

use LWP::UserAgent;
use HTTP::Request;

my $agent = LWP::UserAgent->new(env_proxy => 1,keep_alive => 1, timeout => 30);
my $url = "http://www.theCallingSiteUrl.com/webservice?param1=t1&param2=t2";
my $header = HTTP::Request->new(GET => $url);
my $request = HTTP::Request->new('GET', $url, $header);
my $response = $agent->request($request);

if ($response->is_success){
[do something with] $response->content;


 1:53 pm on Apr 19, 2007 (gmt 0)

I use XML::Simple most of the time but often need XML::Writer to get some complex structures into the right format.
SOAP::Lite is also quite useful for WSDL.
You can convert a chunk of XML into a data structure (of hashes & arrays) using:
my $data = XMLin($xml);


 2:10 pm on Apr 19, 2007 (gmt 0)

Thanks for the heads up spikey, I'll check that one out for my project.


 3:47 pm on Apr 19, 2007 (gmt 0)

Using the HTTP::Request / LWP::UserAgent to make the call and then XML::Simple to process it seems to work pretty well.

Thanks for the help!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved