USING webservice in PHP which returns XML

爱⌒轻易说出口 提交于 2019-12-25 00:17:36

问题


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


回答1:


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);




回答2:


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.



来源:https://stackoverflow.com/questions/974629/using-webservice-in-php-which-returns-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!