How to properly use curl_init for a GET request in PHP? or What's the correct way to handle a curl_in

18 Replies, 1466 Views

"Having trouble with curl_init GET request—any solutions?"

Hey guys,

I’m trying to make a simple curl_init get request in PHP, but it’s not working like I expected.

Here’s what I’ve got:

```php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://example.com/api?param=test");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
```

But the response is empty or errors out. Am I missing something obvious?

Also, is there a better way to handle curl_init get requests? Like, should I be setting more options or checking for errors differently?

Any help would be awesome—thanks in advance!

(PS: If you’ve got a working example, that’d be even better!)

Messages In This Thread
How to properly use curl_init for a GET request in PHP? or What's the correct way to handle a curl_in - by - 16-04-2024, 07:32 AM



Users browsing this thread: 1 Guest(s)