嗨,我试图使用从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