我有一段非常简单的代码,它应该返回一个JSON对象,但没有返回任何值。
当我直接访问url https://api.kraken.com/0/public/Time时,您可以看到所需的JSON输出。
但是,当调用下一个函数(在url https://youreka-virtualtours.be/ethereum/functions.php?call=get_kraken上)时,我没有得到任何输出
<?php
if (isset($_GET['call'])) {
$error = '';
switch($_GET['call']) {
case 'get_kraken':
$url = 'https://api.kraken.com/0/public/Time';
$json = file_get_contents($url);
http_response_code(200);
header('Content-Type: application/json');
echo $json;
break;
}
}
?>
编辑:问题:由于我的file_get_contents的输出与url https://api.kraken.com/0/public/Time显示的不同,我做错了什么?
发布于 2017-06-17 22:45:54
代码运行良好,我在本地进行了测试。这意味着两件事中的一件正在发生。1:您的服务器没有进行file_get_contents调用的能力。2:你的URL不正确,你真的应该回显一些东西以防发生这种情况。试着这样测试一下:
<?php
if(!isset($_GET['call']) || "get_kraken" !== @$_GET['call'] ) {
echo "could not find a valid URL";
}elseif (isset($_GET['call'])) {
$error = '';
switch($_GET['call']) {
case 'get_kraken':
$url = 'https://api.kraken.com/0/public/Time';
$json = file_get_contents($url);
http_response_code(200);
header('Content-Type: application/json');
echo $json;
break;
}
}
?>
https://stackoverflow.com/questions/44605539
复制相似问题