$ch = curl_init("https://www.example.com/api/getUser"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); var_dump($response);
$ch = curl_init("https://www.example.com/api/setUser"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, [ 'name' => 'John Doe', 'email' => 'johndoe@example.com' ]); $response = curl_exec($ch); curl_close($ch); var_dump($response);
$ch = curl_init("https://www.example.com/file.zip"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); $response = curl_exec($ch); curl_close($ch); header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="file.zip"'); echo $response;This example code sends a GET request to download a ZIP file from the specified URL, and sends the file content as a response with the appropriate headers for downloading. Package library for this code: cURL. Overall, the package library used for PHP Request init examples is cURL, which is a PHP library for sending HTTP requests and receiving HTTP responses.