Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

As per the title, I'm using cURL to connect up to my webservice which should then output the response in XML format. cURL is enabled on the server as per my check, however it isn't displaying anything in the response of $xml.

define('SERVICE_URL', 'http://www.myurl.com/webservices/users');
define('USERNAME', 'user');
define('PASSWORD', 'pass');
//define('KEY', 'YOUR_KEY/SID_HERE');

$post = array(
        'UserID' => '5',
        'Name' => 'John',   
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, SERVICE_URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);

curl_close($ch);

$xml = new SimpleXMLElement($result);
echo $xml;
share|improve this question
    
Have you checked for curl errors? –  cale_b May 7 at 2:53
    
@cale_b: I've only checked if it's enabled and it is. I'll try if(curl_errno($c))... now. –  DT.DTDG May 7 at 2:56
    
does it really return valid xml data? kindly check errors on logs. –  Aldee Mativo May 7 at 2:56
    
Unfortunately I don't have access to the server so no error logs. But yes it should return valid xml data as per the documentation displaying a valid xml response. –  DT.DTDG May 7 at 2:57
    
Also try dumping your raw results –  cale_b May 7 at 2:58

1 Answer 1

First, check that $result is actually giving you a result. If it isn't, then your problem isn't with SimpleXMLElement, it's with your curl call.

Second, create an HTML form that sends your data to your URL and check to see that it's actually sending data back. If you aren't getting data, then the problem is with the service, not your curl calls.

Finally, if you're getting data in $result, then check for exceptions in your SimpleXMLElement call:

try {
  $xml = new SimpleXMLElement($result);
}
catch( Exception $e ) {
  echo "found an exception: " . $e;
}
share|improve this answer
    
Thanks @CullyLarson I'll give this a go shortly and advise :) –  DT.DTDG May 7 at 3:02
    
Also, make sure that error reporting is on error_reporting(E_ALL) –  Cully Larson May 7 at 3:05
    
Thanks, will make sure of it! –  DT.DTDG May 7 at 3:06
    
Ok now it's not outputting anything but "Server Error 401 - Unauthorized: Access is denied due to invalid credentials. You do not have permission to view this directory or page using the credentials that you supplied." and the credentials and definitely correct. –  DT.DTDG May 7 at 4:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.