<?php
$url = "http://54.85.96.159:5001/tokens/allocation"; // Ensure the URL includes the protocol

$data = [
    "email" => "dilipkumar.gupta@reseit.in",
    "cost" => 5
];

// Convert data to JSON
$jsonData = json_encode($data);

// Initialize cURL
$ch = curl_init($url);

// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Content-Type: application/json",
    "Accept: application/json"
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // Optional: Increase timeout
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // Optional: Set connection timeout

// Log before sending request
error_log("Sending request to $url with data: " . $jsonData);

// Execute request
$response = curl_exec($ch);

// Check if request was successful
if ($response === false) {
    error_log("cURL request failed: " . curl_error($ch));
} else {
    error_log("Received response: $response");
}

// Check for other cURL errors
if (curl_errno($ch)) {
    error_log("cURL error (" . curl_errno($ch) . "): " . curl_error($ch));
}

// Close cURL
curl_close($ch);

// Print response
echo $response;
?>
