php - curl not working and cant show the print_r data
Get the solution ↓↓↓// buat fungsi http request
function http_request($url){
// persiapan curl
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, $url);
// fungsi transfer nilai yg berupa string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// mematikan ssl verify dan peer verify untuk localhost (ganti valuenya bila sc ini berjalan di hosting
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
// tampung hasil ke dalam variable output
$output = curl_exec($ch);
// tutup curl
curl_close($ch);
// mengembalikan hasil curl
return $output;
}
// panggil fungsi http_request (url / link api)
$data = http_request("https://indonesia-covid-19.mathdro.id/api/provinsi/");
$data = json_decode($data, TRUE);
echo "<pre>";
print_r($data);
echo "</pre>";
?>
why my curl is not working, what the problem? my machine? or my code?
i already try to restart apache, but the problem still persist, curl enabled btw
update: im sorry, the last api service is currently down, but i already change it and the problem still persist, the problem is print_r print nothing, sorry if the question is less to understand, I am a beginner here
pls help me, thanks
Answer
Solution:
It seems like your json_decode($data, TRUE); returns null. Please check that $data is a valid json string before you run this line$data = json_decode($data, TRUE);
, otherwise it will return null, and print_r(null) will print nothing
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: integrity constraint violation: 1452 cannot add or update a child row: a foreign key constraint fails
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.