angelleye Posted May 21, 2007 Share Posted May 21, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/52355-problems-using-pear-http_request-in-combination-with-simplexml/ Share on other sites More sharing options...
angelleye Posted May 23, 2007 Author Share Posted May 23, 2007 I wound up using curl and got it working... Quote Link to comment https://forums.phpfreaks.com/topic/52355-problems-using-pear-http_request-in-combination-with-simplexml/#findComment-260178 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.