1

I'm using a remote API with cURL and querystrings. The issue I'm having is that I can't see the data being returned to me (which is in XML format). To start, here's my code:

$url = 'https://api.somehost.com/GetRequest.do';
$query = 'User=JohnDoe&Password=ABC123&Function=auth';   

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$curlresponse = curl_exec($ch);

I know the cURL request is working because if I change the password to something incorrect, I get a response back (can see it using print_r($curlresponse) telling me the password is incorrect.

However, when I enter the correct password, I see nothing when I print_r($curlresponse) yet I know I'm receiving the data because a print_r(curl_getinfo($ch)) shows a larghe download_content_length which is the data I'm expecting. The data I'm expecting back is in XML format. I'm just not sure what I'm missing.

Thank you!

Jason
  • 1,105
  • 3
  • 16
  • 30
  • What is the response HTTP code? `$http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE);` – user1190992 Jan 23 '13 at 15:13
  • I get a 200 response code... – Jason Jan 23 '13 at 15:15
  • [This](http://stackoverflow.com/a/563271/1190992) could help .. – user1190992 Jan 23 '13 at 15:22
  • OK - that definitely helped. Seems the output was just being hidden by the browser. I just added `echo htmlspecialchars($curlresponse);` and I can see the output. One last question if I could....the output has several values like this: ``. If I want to get a specific value (Software Quota Available, for example), how do I retrieve that from the output? – Jason Jan 23 '13 at 15:35
  • You need to use something like [SimpleXMLElement attributes method](http://php.net/manual/en/simplexmlelement.attributes.php). – user1190992 Jan 23 '13 at 15:48
  • 1
    Perfect - thank you. Got it to work with: `$parsedresponse = simplexml_load_string($curlresponse); htmlspecialchars($parsedresponse->Software['Quota']);` Thank you for all your help! – Jason Jan 23 '13 at 15:52

0 Answers0