开发者

Curl stopped working all of a sudden

I was working on a project for which i was using curl to fetch some data from a website (more so like a API call). Two nights ago I checked everything and it was working smoothly but all of a sudden yesterday morning I started getting an error:

A PHP Error was encountered

Severity: Warning

Message: DOMDocument::loadXML() [domdocument.loadxml]: Empty string supplied as input

Filename: controllers/user.php

My code is:

$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data=curl_exec($ch);
curl_close($ch);
$doc = new DOMDocument();
$doc->loadXML($data);
$doc->save("test2.xml");

The url is correct as the everything was working 2 days ago!

I am working on wamp server currently and php_curl is enabled!

开发者_JAVA百科

This is the API i am trying to call! Is there any other method to send the request and fetch the data apart from curl?


As an alternate try echo file_get_contents($url);

Also see what you get if you do something like this:

$data=curl_exec($ch);
echo curl_error($ch);
echo "<br>";
$info = curl_getinfo($ch);
print_r($info);
curl_close($ch);

The curl info and curl error might give you some insight about the request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜