0

I am using a webservice to get some results in XMl form... here is the part of the code

public function getXML()
{
    $url=$this->constructURL();
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $xml = curl_exec($ch);
    if ($error = curl_error($ch)) {
    echo "Error: $error<br />\n";
    }
    curl_close($ch);
    return $xml;
}


$resultXML = $api->getXML();
echo $resultXML;

when i echo that '$asd' it does nothing but a balnk page...

but when i use the value of $url directly in the browser it produce an XML result...

can any one suggest me where i am going wrong???

ADDED.........

when i included the error reporting after curl_exec

it gives an error

Error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

also Iam usig https://blahblh for request

3
  • 1
    Does cURL work with any other URL? Have you set error_reporting and display_errors properly? Commented Jun 10, 2009 at 9:55
  • yes, I am using yahoo spel check service...and curl works fine with it. Also i havent set error reporting yet Commented Jun 10, 2009 at 10:00
  • while developing you should ALWAYS display all errors, notices, etc. now you know why :-) Commented Jun 10, 2009 at 10:59

2 Answers 2

4

Solved Out The PROBLEM....

since i am using https:// ,i Have to include a single line of code which set the cURL options

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much - I had been trying to solve this for hours.
1

I i'm not blind - your "getXML" is a method of a class (ie myWebService). So, how do you think your $asd = getXML(); should work?

I suppose your code must look like this:

...
$service = new myWebService();
$asd = $service->getXML();
echo $asd;

ADDED:

I think, that browser just doesn't display your XML, because it receives a header with content-type text/html by default. Try to look at page source or write before echo

header('Content-type: text/xml');

Any browser, assuming that this is HTML should ignore unknown tags which are not HTML-compatible. So your XML is being interpreted as unknown non-HTML tag.

3 Comments

I know tht.... I have created a class for my service and called getXML through an object of tht class....
i haven't posted all the code in the question. only the relevant part
when i added the header('Content-type: text/xml'); i got XML Parsing Error: not well-formed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.