Description
This script is a web service proxy to get around some of the usual cross-domain issues common in Ajax applications.
Code Sample:
#!/usr/local/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use LWP::UserAgent;
use HTTP::Request;
use strict;
use warnings;
my $cgi = new CGI;
my $ws = $cgi->param( 'ws' );
## Define the User Agent Object
my $agent = LWP::UserAgent->new( env_proxy => 1,keep_alive => 1, timeout => 30 );
## The web service url is passed into the script to be more generic
my $url = $ws;
my $header = HTTP::Request->new( GET => $url );
my $request = HTTP::Request->new( 'GET', $url, $header );
my $response = $agent->request( $request );
## XML Header
print $cgi->header( 'text/xml' );
if ( $response->is_success ){
## Simply spit it back out, nothing special needed
print $response->content;
}
else {
## This error message isn't extremely helpful, I'll expand it
my $error = qq{<h3>It didn't work</h3>};
print $error;
}