Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php json curl获取请求Drupal 7_Php_Json_Curl_Drupal 7 - Fatal编程技术网

Php json curl获取请求Drupal 7

Php json curl获取请求Drupal 7,php,json,curl,drupal-7,Php,Json,Curl,Drupal 7,我正在尝试使用Drupal7中的curl方法从外部url检索json数据。 因此,我有检索数据的函数: ////jSON URL which should be requested $gry_str = "?timezone=".urlencode(date_default_timezone_get()) ."&dateFrom=".date('Y-m-d')."&dateTill=".date('Y-m-d'); $json_url = 'http:/

我正在尝试使用Drupal7中的curl方法从外部url检索json数据。 因此,我有检索数据的函数:

////jSON URL which should be requested
$gry_str = "?timezone=".urlencode(date_default_timezone_get())
            ."&dateFrom=".date('Y-m-d')."&dateTill=".date('Y-m-d');

$json_url = 'http://www.example.com/json/financial-calendar.json'.$gry_str;
// Initializing curl
$ch = curl_init(); 

//Configuring curl options 
$options=array(CURLOPT_RETURNTRANSFER => true, 
                CURLOPT_HTTPHEADER => array('Content-type: application/json'),
                CURLOPT_URL => $json_url);

//Setting curl options
curl_setopt_array($ch, $options);

//Getting resutls
$results = curl_exec($ch); //Getting json result string
curl_close($ch);
当我尝试加载或刷新页面时,firebug会显示标题和参数,但不会显示响应和html。 它还显示状态200 Ok

当我尝试回显url并在web浏览器上测试它时,它会正确显示数据数组。我试图将检索到的数据显示到html表中,但没有成功

我不知道错误在哪里,甚至不知道我在drupal中是不是用正确的方式做的。
请帮助..我迷路了。

执行此代码回送文件时会发生什么;而不是使用卷曲?这是一样的!它在我的主页的最顶端打印外部url的内容。Firebug中的响应仍然是空的。我做错什么了吗??drupal是否使用了与我不同的东西?我不知道错误在哪里!请注意,我在本地主机上使用的是WAMP服务器。您是否使用Ajax调用Drupal菜单路径,然后调用外部URL获取JSON并将响应返回到前端?我不认为路径有问题,因为当我回显外部URL时,JSON文件的结果会打印在页面顶部。无论如何,json文件都位于主机上,开发完成后,我将托管我的网站。你说我使用Ajax调用菜单路径,然后调用外部URL来获取JSON文件是什么意思?我还阅读了关于创建一个模块的内容,该模块将使用hook_菜单使用curl检索JSON。你指的是这个吗?