【发布时间】:2014-06-30 22:53:22
【问题描述】:
所以我有这个代码:
$url = "https://..."; //a valid url, showing without errors a correct XML
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
/* to which i added the following */
curl_setopt($handle, CURLOPT_CAPATH, "http://curl.haxx.se/ca/cacert.pem");
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, TRUE);
$result = curl_exec($handle);
$resultXml = new SimpleXMLElement($result); //Line 47
/* tests */
var_dump($handle); echo "<br/><br/>"; //resource(11) of type (curl)
var_dump($url); echo "<br/><br/>"; //string(149) "https://..." (exactly $url)
var_dump($result); echo "<br/><br/>"; //bool(false)
这会产生这个错误:
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' [...] on line 47
Stack trace:
#0 C:\yy.php(47): SimpleXMLElement->__construct('')
#1 C:\xx.php(23): Integrator->Integrator('numbers', Object(Database))
#2 {main}
thrown [...] on line 47
var_dump() 返回的是 cmets。
使用它,我们可以看到 $result 是空的;这是主要问题!
我一开始以为问题出在页面的https连接上,所以在中间加了3行;问题依旧。
现在我想知道我的 SSL 证书(来自 Gandi SAS)是否没有明确包含在 http://curl.haxx.se/ca/cacert.pem 中是问题所在。 如果是这样,我如何告诉 CURLOPT_CAPATH 获取我的证书?
其他地方有错误吗?
感谢您的帮助!
【问题讨论】: