Welcome to WebmasterWorld Guest from 54.226.246.160

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

     

agentalpha

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

5+ Year Member



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?

Dabrowski

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

WebmasterWorld Senior Member 5+ Year Member



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.

rocknbil

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

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



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

phranque

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

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



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;
}

spikey

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

10+ Year Member



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);

Dabrowski

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

WebmasterWorld Senior Member 5+ Year Member



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

agentalpha

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

5+ Year Member



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!

 

Featured Threads

Hot Threads This Week

Hot Threads This Month