嗨,我試圖使用從JSON文件從URL數據捲曲和PHP使用此代碼來獲得:通過捲曲從URL獲取JSON以https返回Null
<?php
// Initiate curl
$url = "https://panel.virtualcenter360.es/home/api/getdatasample?dateIni=1376524800&dateEnd=1381795200";
$ch = curl_init($url);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
$res = iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode($result));
var_dump(json_decode($res, true));
switch (json_last_error()) {
case JSON_ERROR_NONE:
echo ' - No errors';
break;
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
echo ' - Unknown error';
break;
}
curl_close($ch);
?>
,我發現了沒有錯誤消息,但爲NULL結果。你認爲這可能是什麼問題?
也許我需要從Curl配置一些參數?
謝謝!
我還試圖與file_get_contents()函數,如:$結果=的file_get_contents('https://panel.virtualcenter360.es/home/API/getdatasample dateIni = 1376524800&dateEnd = 1381795200' )?; var_dump(json_decode($ result,true));但我得到錯誤。 – victorgb6
'$ result = file_get_contents('https://panel.virtualcenter360.es/home/api/getdatasample?dateIni=1376524800&dateEnd=1381795200'); var_dump(json_decode($ result,true));'對我來說工作正常。我建議你使用[高級REST客戶端](https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo)對Chrome或其他測試工具進行試用。 – JayEffKay
嗨,我已經嘗試過在線服務器中的file_gets_contents,它的工作原理。我認爲它是從本地主機服務器嘗試的問題。謝謝! – victorgb6