PHP XML-XML curl function not working. Please help
am 11.04.2008 13:25:47 von rajHi Everyone,
I'm trying to get the following php script to work with an ebay API. It
sends XML and then returns XML and formats it into links. THing is it
doesn;t work, and I'm not sure why. Can anyone see where I'm going
wrong?
Thank you in advance,
Raj
$query = 'ipod';
$endpoint = 'http://open.api.ebay.com/shopping?';
$resp =
simplexml_load_string(constructPostCallAndGetResponse($endpo int,
$query));
if ($resp) {
$results = '';
foreach($resp->Item as $item) {
$link = $item->ViewItemURLForNaturalSearch;
$title = $item->Title;
$results .= "
";
}
}
else {
$results = "Oops! Must not have gotten the response!";
}
?>
eBay Search Results for
eBay Search Results for
function constructPostCallAndGetResponse($endpoint, $query)
{
$xmlRequest = "";
$xmlRequest .= "
$xmlRequest .= "
$xmlRequest .= $query;
$xmlRequest .= "
$session = curl_init($endpoint); // create a
curl session
curl_setopt($session, CURLOPT_POST, true); // POST request type
curl_setopt($session, CURLOPT_POSTFIELDS, $xmlRequest); // set the
body of the POST
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // return
values as a string - not to std out
$headers = array(
'X-EBAY-API-CALL-NAME: FindItemsAdvanced',
'X-EBAY-API-SITEID: 0', // Site 0
is for US
'X-EBAY-API-APP-ID: My ID Goes Here. Removed for security',
'X-EBAY-API-VERSION: 559',
"X-EBAY-API-REQUEST-ENCODING: XML",
'Content-Type: text/xml;charset=utf-8',
);
curl_setopt($session, CURLOPT_HTTPHEADER, $headers); //set
headers using the above array of headers
$responseXML = curl_exec($session); // send the request
curl_close($session);
return $responseXML; // returns a string
} // function
?>