cURL GET Request in PHP
Issue a GET request with libcurl wrappers and capture the body.
Author:
chris
// Language: PHP
<?php
declare(strict_types=1);
$ch = curl_init('https://api.github.com/zen');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'code-snippets/1.0',
CURLOPT_TIMEOUT => 10,
]);
$body = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
echo "$code\n$body\n";