已提出此問題。但其中的任何一個都不適合我。當CURL調用始終進行時,我變爲NULL。PHP CURL調用始終顯示NULL
以下是我的list_clients.php文件。
<?php
require_once 'init.php';
header('Content-Type: application/json');
$clientResults = mysqli_query($link, "SELECT * FROM clients");
$clients = array();
while($client = mysqli_fetch_assoc($clientResults)){
$clients[] = $client;
}
echo json_encode($clients);
exit;
所以上面的輸出是:
[{"ip_address":"192.168.177.137","mac_address":"3a:1a:cf:7c:92:89","added_on":"2017-08-19 12:48:34"},{"ip_address":"192.168.177.137","mac_address":"3a:1a:cf:7c:92:89","added_on":"2017-08-20 08:09:29"}]
以下是我curl_call.php文件
<?php
$url = 'http://127.0.0.1/testing/list_clients.php';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_HTTPGET, TRUE);
curl_setopt($curl, CURLOPT_HEADER, 0);
//curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
//curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type : application/json',
'Accept: application/json'
));
$clientResult = curl_exec($curl);
if($clientResult == FALSE) {
var_dump(curl_error($curl));
}
curl_close($curl);
var_dump($clientResult); //For this line I am getting the following image eror
$clients = json_decode($clientResult, TRUE);
var_dump($clients);
如果我var_dump($clientResult);
然後我收到以下錯誤
它一直在顯示NULL。什麼可能導致錯誤。
'$ clientResult'的輸出是false還是null? – hassan
你在你的'list_clients中完成了'$ clients'的'var_dump()'嗎?php'確保它不是實際爲空? –
啓用錯誤報告。 – Cyclonecode