homepage Welcome to WebmasterWorld Guest from 54.227.141.230
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
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
agentalpha




msg:3314612
 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:
[theCallingSiteUrl.com...]

Any ideas?

 

Dabrowski




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

rocknbil




msg:3315024
 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.)

phranque




msg:3315590
 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;
}


spikey




msg:3315715
 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);

Dabrowski




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

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

agentalpha




msg:3315861
 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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved