Forum Moderators: coopster & phranque

Message Too Old, No Replies

POSTing to an external URL via Perl

for the eBay API

         

Tonearm

12:12 am on Sep 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm trying to use the eBay API with my online store and to do that I need to be able to post a series of HTTP headers and an XML request to a URL. I've got that all set up, but when making the request I only get the headers back from eBay and not the XML response I'm supposed to get with the headers. I've asked about this on the eBay developer forums and one guy says that when he makes a request and only sends the headers, he only gets back the headers, just like in my case. So I'm thinking the Perl I'm using to make the request may be flawed and is only sending the headers. My store is built on an open-source shopping cart called Interchange. It allows you to create "usertags" and that's what I'm using to make the request. Here's the "post-external" usertag:

<<EOR
use HTTP::Request::Common;
use LWP::UserAgent;
sub {
my ($uri,$f,$h,$timeout,$useragent) = @_;
die q{No URI provided to the "post-external" UserTag} unless $uri;

$timeout ¦¦= 30;
$useragent ¦¦= 'post-external';

my %headers = ();
foreach (split(/[\r\n]+/,$h)) {
/^\s*(.+?)\s*[=:]\s*(.*?)\s*$/;
$headers{$1} = $2 if (length($1) && length($2));
}

my %form = ();
foreach (split(/[\r\n]+/,$f)) {
/^\s*(.+?)\s*[=:]\s*(.*?)\s*$/;
$form{$1} = $2 if (length($1) && length($2));
}

my $ua = new LWP::UserAgent(
timeout => $timeout,
agent => $useragent,
);

my $res = $ua->request(POST($uri,\%form,%headers));
die $res->message() unless $res->is_success();

return $res->as_string();
}
EOR

and I'm calling that usertag on a test page with the following code:

[post-external
form=¦
request=<?xml version='1.0' encoding='iso-8859-1'?>
<request xmlns="urn:eBayAPIschema"><RequestUserId>testuser</RequestUserId>
<RequestPassword>testpassword</RequestPassword><DetailLevel>0</DetailLevel><ErrorLevel>1</ErrorLevel>
<SiteId>0</SiteId><Verb>GeteBayOfficialTime</Verb></request>
¦
headers=¦
X-EBAY-API-COMPATIBILITY-LEVEL: 305
X-EBAY-API-SESSION-CERTIFICATE: certificate
X-EBAY-API-DEV-NAME: devname
X-EBAY-API-APP-NAME: appname
X-EBAY-API-CERT-NAME: certname
X-EBAY-API-CALL-NAME: GeteBayOfficialTime
X-EBAY-API-SITEID: 0
X-EBAY-API-DETAIL-LEVEL: 0
Content-Type: text/xml
Content-Length: length($request)
¦
uri=https://api.sandbox.ebay.com/ws/api.dll
timeout=30
]

I know you guys can't comment on anything but the Perl syntax/functionality, but that's OK, I think that must be where the problem lies. I'd REALLY appreciate any help you guys can lend on this one. I've been working on this for a while now.

[edited by: jatar_k at 6:13 pm (utc) on Sep. 13, 2003]
[edit reason] broke line for sidescroll [/edit]

Tonearm

10:50 pm on Sep 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Before somebody reads through this big ugly post, I'm happy to report that I've got it working. In other words: never mind!