fork download
  1. <?php
  2. $url = "http://54.85.96.159:5001/tokens/allocation"; // Ensure the URL includes the protocol
  3.  
  4. $data = [
  5. "email" => "dilipkumar.gupta@reseit.in",
  6. "cost" => 5
  7. ];
  8.  
  9. // Convert data to JSON
  10. $jsonData = json_encode($data);
  11.  
  12. // Initialize cURL
  13. $ch = curl_init($url);
  14.  
  15. // Set cURL options
  16. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  17. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  18. "Content-Type: application/json",
  19. "Accept: application/json"
  20. ]);
  21. curl_setopt($ch, CURLOPT_POST, true);
  22. curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
  23. curl_setopt($ch, CURLOPT_TIMEOUT, 30); // Optional: Increase timeout
  24. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // Optional: Set connection timeout
  25.  
  26. // Log before sending request
  27. error_log("Sending request to $url with data: " . $jsonData);
  28.  
  29. // Execute request
  30. $response = curl_exec($ch);
  31.  
  32. // Check if request was successful
  33. if ($response === false) {
  34. error_log("cURL request failed: " . curl_error($ch));
  35. } else {
  36. error_log("Received response: $response");
  37. }
  38.  
  39. // Check for other cURL errors
  40. if (curl_errno($ch)) {
  41. error_log("cURL error (" . curl_errno($ch) . "): " . curl_error($ch));
  42. }
  43.  
  44. // Close cURL
  45.  
  46. // Print response
  47. echo $response;
  48. ?>
  49.  
Success #stdin #stdout #stderr 0.04s 25844KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Sending request to http://54.85.96.159:5001/tokens/allocation with data: {"email":"dilipkumar.gupta@reseit.in","cost":5}
cURL request failed: 
cURL error (7):