How to properly use curl_init for a GET request in PHP? or Why is my curl_init GET request not workin

24 Replies, 2035 Views

Your code’s good, but for better error handling, wrap it in a try-catch and check the HTTP code:
```php
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode != 200) {
throw new Exception("API returned $httpCode");
}
```
Makes debugging way easier.

Messages In This Thread



Users browsing this thread: 1 Guest(s)