PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Trouble with HTTP_Request. Can't seem to make it work..??

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> HTTP
View previous topic :: View next topic  
Author Message
angelleye



Joined: 22 May 2007
Posts: 3

PostPosted: Tue May 22, 2007 2:23 am    Post subject: Trouble with HTTP_Request. Can't seem to make it work..?? Reply with quote

I'm new to PHP and I'm trying to do some simple xml web service requests and responses. I'm trying to use PEAR's HTTP_Request package to handle the requests and store the response in a variable that I can later use to parse. This very basic example works just fine for me...

Code:

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

$req =& new HTTP_Request();
$req -> setURL("http://angelleye.sytes.net:8080/htdocs/parsexmldata.xml");
$req -> sendRequest();

$xmlResponse = simplexml_load_string($req -> getResponseBody());

foreach ($xmlResponse -> xpath('/People/Person') as $Person)
   {
      $FirstName = $Person -> FirstName;
      $LastName = $Person -> LastName;
      echo $FirstName . " " . $LastName . "<br />";
   }

?>


It does exactly what's expected and prints the full name of each <Person> on their own line. So now I'm trying to figure out how to include an XML request and store the XML response in a variable to load into SimpleXML rather than calling an XML document directly like that working sample does. Here's what I've got...

Code:

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

$eBayAPICallName = "GeteBayOfficialTime";
$APIURL = "https://api.sandbox.ebay.com/ws/api.dll";
$DevID = "MY_DEV_ID";
$AppID = "MY_APP_ID";
$Cert = "MY_CERT";
$AuthToken = "MY_AUTH_TOKEN";

//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("xmlRequest", $requestXMLBody, 1);
$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");
$req -> sendRequest();

$xmlResponse = simplexml_load_string($req -> getResponseBody());

echo $xmlResponse -> asXML();

?>


This is returning a blank white browser page with nothing but the basic empty HTML tags inside it...

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY>
<META content=FUGCLQURCL name=SKYPE_FRAMEID></HTML>


I don't ever get any errors either. Any information I can get on what I'm doing wrong here would be greatly appreciated. Right now it should simply list the data in the browser from the echo line but that's not happening. Please help, I'm as lost as ever. Thanks!
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1235

PostPosted: Tue May 22, 2007 9:23 am    Post subject: Reply with quote

Turn error reporting on and you should see what the problems are:
Code:

ini_set('display_errors', 1);
error_reporting(E_ALL);


And one error is obvious:
Code:

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

(this should lead to a parse error; use \" instead of "")
Back to top
View user's profile Send private message
angelleye



Joined: 22 May 2007
Posts: 3

PostPosted: Tue May 22, 2007 8:21 pm    Post subject: ok... Reply with quote

thanks for the tip on errors. I added that and sure enough got errors on the xml string. I fixed those as you said and now I can successfully print the XML string to the browser (actually only the data displays but if i view source i see all the XML).

So now I'm getting no errors at all again but the HTTP request is still seemingly doing nothing. I've tried returning the body and the response and I get nothing...which leads me to believe the request must not be getting sent at all. However, i'm doing that part the same way I did on the working sample script, it just has some extra things like all the headers. Headers are pretty basic, though, and they match the headers of the working ASP script I have so that part should be good. That leaves me with setMethod() and addPostData() as possible problems.

In the sample script that is working I don't include setMethod(HTTP_REQUEST_METHOD_POST);

I tried commenting that out of this other script and it didnt help so I went ahead and added it back. Which leaves me with addPostData().

From the documentation it looks to me like I've got that setup correctly. the last paramater that shows whether or not the string is URLEncoded already or not is a little confusing to me. It says the default is false...so what is it doing then..?? An XML string doesn't ahve to be URL encoded does it? I tried setting that to true and I got the same result.

So again, no errors and no response. Anything you can tell me would be awesome. Thanks![/i]
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1235

PostPosted: Tue May 22, 2007 9:05 pm    Post subject: Reply with quote

Sorry, no more ideas from me about this problem. I don't know the package, and could only give you the general hints on error handling.

I can only add that it might help to debug your problem, if you add:
Code:
PEAR::setErrorHandling(PEAR_ERROR_DIE);
Back to top
View user's profile Send private message
angelleye



Joined: 22 May 2007
Posts: 3

PostPosted: Wed May 23, 2007 8:53 am    Post subject: ok Reply with quote

well, i got curl configured and it's working great with that. if anybody can ever tell me why this wasn't working that'd be cool. thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> HTTP All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement