How to properly use CURL_INIT for a GET request? or Why is my CURL_INIT GET request not working as ex

16 Replies, 1047 Views

CURL_INIT GET requests are straightforward once you see a working example. Here’s one:

```php
$ch = curl_init("https://official-joke-api.appspot.com/random_joke");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$joke = curl_exec($ch);
curl_close($ch);
echo $joke;
```

RETURNTRANSFER is essential unless you want the response to print automatically (which is rarely useful).

If you’re tired of cURL’s verbosity, check out HTTPful (a lightweight PHP lib).

Messages In This Thread



Users browsing this thread: 1 Guest(s)