Welcome to WebmasterWorld Guest from 54.147.134.218

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

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)

New User

5+ Year Member

joined:June 5, 2006
posts:18
votes: 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:
[theCallingSiteUrl.com...]

Any ideas?

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

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 29, 2007
posts:1147
votes: 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)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 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)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10543
votes: 8


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)

Junior Member

10+ Year Member

joined:June 20, 2003
posts:65
votes: 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)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 29, 2007
posts:1147
votes: 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)

New User

5+ Year Member

joined:June 5, 2006
posts:18
votes: 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!

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members