我有一段非常簡單的代碼,它應該返回一個JSON對象,但不返回任何值。php file_get_contents不返回值
當我直接訪問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顯示
而你的問題是? – hakre
使用curl而不是file_get_contents來檢查響應http代碼,它可以幫助您調試問題出在哪裏。 –
**我得到** SyntaxError:JSON.parse:JSON數據第1行第3列的數據意外結束 – RiggsFolly