|
#!/usr/local/bin/perl
$SubscriptionId = 'o^ID';
use XML::DOM;
require HTTP::Request;
require LWP::UserAgent;
$METHOD = $ENV{'REQUEST_METHOD'};
$METHOD =~ tr/a-z/A-Z/;
$QUERY_STRING = $ENV{'QUERY_STRING'};
if ( $METHOD eq "POST" ) {
read(STDIN, $Form, $ENV{'CONTENT_LENGTH'});
@Fields_Data = split(/&/, $Form);
}
@Fields_Data2 = split(/&/, $QUERY_STRING);
foreach $Field_Data ( @Fields_Data ) {
($Name, $Value) = split(/=/, $Field_Data);
$Value =~ tr/+/ /;
$Value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$_POST{$Name} = $Value;
}
foreach $Field_Data2 ( @Fields_Data2 ) {
($Name, $Value) = split(/=/, $Field_Data2);
$Value =~ tr/+/ /;
$Value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$_POST{$Name} = $Value;
$_GET{$Name} = $Value;
}
if ( $_POST{'send'} eq 'Direct XML' ) {
DirectXML();
exit();
}
print "Content-Type: text/html; Charset=shift_jis\n";
print "\n";
sub DirectXML {
print "Content-Type: text/plain; Charset=utf-8\n";
print "\n";
$req =
"http://webservices.amazon.co.jp/onca/xml?" .
"Service=AWSECommerceService&" .
"SubscriptionId=$SubscriptionId&" .
"Operation=ItemLookup&" .
"ResponseGroup=Large&" .
"ItemId=" . $_POST{'ISBN'};
$request = HTTP::Request->new("GET", $req );
$ua = LWP::UserAgent->new;
$response = $ua->request($request);
$parser = new XML::DOM::Parser;
$doc = $parser->parse($response->content);
$nodes = $doc->getElementsByTagName ("Items");
PrintNode( $nodes );
}
sub PrintNode {
local($nodes) = $_[0];
local($nCount) = $nodes->getLength();
local($i) = 0;
local($node);
local($nodeList);
for ( $i = 0; $i < $nCount; $i++ ) {
$node = $nodes->item($i);
if ( $node->hasChildNodes ) {
$nodeList = $node->getChildNodes();
PrintNode( $nodeList );
}
else {
print $node->getNodeValue . "\n";
}
}
}
| |