note 127266 deleted from book.curl by cmb
| From: | cmb@php.net | Date: | Tue, 12 Jul 2022 08:46:17 +0000 |
| Subject: | note 127266 deleted from book.curl by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218979@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
function curl_request($url, $method = 'get', $data = [], $type = 'https')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (strtolower($method == 'post')) {
$data = json_encode($data);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
if (strtolower($type) == 'https') {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
$result = curl_exec($ch);
if ($result == null || $result === false) {
print_r(curl_error($ch));
}
curl_close($ch);
return $result;
}