'Warning: Attempt to read property "items" on null
I am trying to get JSON data through an API url (if you enter to the API link you'll see the JSON).
When I use a localserver for the API (I use Xampp) it gets the data perfectly, but when i try to get the data through the API hosting it detects it as NULL
I need to use the API hosting, anyone knows how to fix this? is the problem the API hosting? if it its what free hosting can I use for the API? (I'm using InfinityFree)
<?php
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$api_url = 'https://proyecto-idts6.epizy.com/models/get.php'; //<-THIS ONE DOESN'T WHORKS ❌ (WHY?)
//$api_url = 'http://localhost:84/API-ios/models/get.php'; <-THIS ONE WORKS ✅
$json_data = file_get_contents($api_url, false, stream_context_create($arrContextOptions));
$datos = json_decode($json_data)->items;
?>
<table>
<thead>
<tr>
<th>Name</th>
<th>Category</th>
<th>Price</th>
<th>Description</th>
<th>Stock</th>
</tr>
<?php
foreach($datos as $data) {
?>
<tr>
<td><?php echo ($data->nombre) ?></td>
<td><?php echo ($data->categoria) ?></td>
<td><?php echo ($data->precio) ?></td>
<td><?php echo ($data->descripcion) ?></td>
<td><?php echo ($data->stock) ?></td>
</tr>
<?php
}
?>
</thead>
</table>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
