Jump to content

Problems using PEAR HTTP_Request in combination with SimpleXML...???


Recommended Posts

I'm just beginning with PHP and I'm trying to figure out how to handle HTTP Requests/Response with web services such as eBay and PayPal.  In my research I've come across HTTP_Request included with PEAR.  I've gotted it installed and tested successfully with the following:

 

<?php

require_once "HTTP/Request.php";

 

$req =& new HTTP_Request("http://www.ebay.com/");

if (!PEAR::isError($req->sendRequest()))

      {

            echo $req->getResponseBody();

      }

?>

 

That displays ebay's web site when I load the page so it seems that PEAR is working correctly.

 

I'm trying now to move on and do an actual call to their API.  It's the easiest call you can make with their API and it simply returns the official eBay time.  Here is what I've got:

 

<?php require_once "HTTP/Request.php";?>

 

<?php

$eBayAPICallName = "GeteBayOfficialTime";

$APIURL = "https://api.ebay.com/ws/api.dll";

$DevID = "My_Dev_ID_Here";

$AppID = "My_App_ID_Here";

$Cert = "My_Cert_Here";

$AuthToken = "My_Auth_Token_Here";

 

//eBay GetOfficialTime request

$requestXMLBody = "<?xml version=""1.0"" encoding=""utf-8""?>";

$requestXMLBody .= "<GeteBayOfficialTimeRequest xmlns=""urn:ebay:apis:eBLBaseComponents"">";

$requestXMLBody .= "<RequesterCredentials>";

$requestXMLBody .= "<eBayAuthToken>" . $AuthToken . "</eBayAuthToken>";

$requestXMLBody .= "</RequesterCredentials>";

$requestXMLBody .= "</GeteBayOfficialTimeRequest>";

 

$req =& new HTTP_Request();

$req -> setURL($APIURL);

$req -> setMethod(HTTP_REQUEST_METHOD_POST);

$req -> addPostData($requestXMLBody);

$req -> addHeader("X-EBAY-API-COMPATIBILITY-LEVEL", "511");

$req -> addHeader("X-EBAY-API-SESSION-CERTIFICATE", $DevID . ";" . $AppID . ";" . $Cert);

$req -> addHeader("X-EBAY-API-DEV-NAME", $DevID);

$req -> addHeader("X-EBAY-API-APP-NAME", $AppID);

$req -> addHeader("X-EBAY-API-CERT-NAME", $Cert);

$req -> addHeader("X-EBAY-API-CALL-NAME", $eBayAPICallName);

$req -> addHeader("X-EBAY-API-SITEID", "0");

$req -> addHeader("X-EBAY-API-DETAIL-LEVEL", "0");

 

$XMLResponse = simplexml_load_string($req -> sendRequest());

 

echo $XMLResponse -> asXML();

 

?>

 

The idea behind this (from what i can piece together from tutorials and everything I've been studying) is that it constructs the basic XML string to use and uses PEAR's HTTP_Request to send it off.  I'm storing the response in $XMLResponse with the SimpleXML PHP function hoping I could display the XML response in the browser to ensure things are working....but they're not.

 

When I run this page I get a blank white browser back.  View source has nothing but the empty basic html tags.  All of the headers I've added were taken from working ASP scripts so know those are good (unless I've just done something wrong with syntax there or something). 

 

I've tested the simplexml stuff successfully using basic XML files located on my disk so I thought I had that setup correctly too.  Obviously something is wrong somewhere, though.

 

Any information I can get on what I'm doing wrong here would be greatly appreciated.  Thanks!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.