http reqeust sample code

 

case 1.

<?php

$url = 'https://www.example.com/api/endpoint';

// Use file_get_contents to make the request
$response = file_get_contents($url);

// Check if the request was successful
if ($response === false) {
    echo "Request failed.";
} else {
    echo "Request succeeded: $response";
}

 

case 2.

<?php

$url = 'https://www.example.com/api/endpoint';

// Create a cURL handle
$ch = curl_init();

// Set the URL
curl_setopt($ch, CURLOPT_URL, $url);

// Return the response as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Make the request
$response = curl_exec($ch);

// Check if the request was successful
if (curl_errno($ch)) {
    echo "Request failed: " . curl_error($ch);
} else {
    echo "Request succeeded: $response";
}

// Close the cURL handle
curl_close($ch);