fork download
  1. <?php
  2.  
  3. $ch = curl_init();
  4.  
  5. $api_url = "https://j...content-available-to-author-only...e.com/posts/1"; // Example API URL
  6. curl_setopt($ch, CURLOPT_URL, $api_url);
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  8.  
  9. $response = curl_exec($ch);
  10.  
  11. if (curl_errno($ch)) {
  12. $error_msg = curl_error($ch);
  13. echo "cURL Error: " . $error_msg;
  14. } else {
  15. $data = json_decode($response, true);
  16. if ($data) {
  17. echo "API Response:\n";
  18. print_r($data);
  19. } else {
  20. echo "Failed to decode JSON response.\n";
  21. echo "Raw response: " . $response;
  22. }
  23. }
  24.  
  25.  
  26. ?>
Success #stdin #stdout 0.03s 26344KB
stdin
Standard input is empty
stdout
cURL Error: Could not resolve host: jsonplaceholder.typicode.com