. Topicala Page Index Token

A Journal about the experiences I have developing little applications in C#, Perl, Html and Javascript and talking about things new things that I use. Always Geeky; Always Nerdy; Always poor Grammer!

I am a Software Analyst Developer working in Southport, England but living in Liverpool. I develop mainly in C# and ASP.Net. I have been developing comercial software for several years now. I maintain this site (hosted at SwitchMedia UK) as a way of exploring new technologies (such as AJAX) and just generally talking about techie geek issues. This site is developed through a host of Perl scripts and a liberal use of Javascript. I enjoy experimenting with new technologies and anything that I make I host here.

Quick Search

Web www.kinlan.co.uk

Saturday, August 27, 2005

Proxy Script To Yahoo API Term Extraction

Finally, here it is after a busy week.

What follows is a listing of the code I created to create a proxy that would allow me to access the Yahoo API from any browser with out having to worry about Cross Site Scripting.

This works in Internet Explorer (IE6, IE7) and firefox, and is used in my AJAX example.

Bascially, it retrieves a POST request from the browser and forwards the result inside another POST request to Yahoo, once I recieve the response, I pass back the XML to the web browser.

And thats it really.

Do you have any Questions, email me: Paul Kinlan [paul.kinlan@gmail.com]

#!/usr/bin/perl
use LWP;
use CGI qw(:standard);
$CGI::POST_MAX=1024 * 100; # max 100K posts
my($qCGI) = new CGI();
my($YahooAppID) = "APPIDHERE";

my($baseUrl) = "http://api.search.yahoo.com/
ContentAnalysisService/V1/termExtraction";

my($context)= $qCGI->param('context');
my($query) = $qCGI->param('query');
my($finalUrl) = $baseUrl ;

$ua = LWP::UserAgent->new;
$ua->agent("YahooPassThrough/0.1 ");

# Create a request
my $req = HTTP::Request->new(POST => $finalUrl);
$req->content("appid=".$YahooAppID."&context=".$context."&query".$query);
$req->content_type('application/x-www-form-urlencoded');

# Pass request to the user agent and get a response back
my $res = $ua->request($req);
print "Content-type: text/xml\n\n";
print $res->content;

Technorati Tags
[feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed]

Comments: [Add New]