curlexec.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. function CURLrequestGET($url, $customHeaderStringArray='', $params = [])
  3. {
  4. $headers = array("Content-Type: application/json", "Accept:application/json");
  5. foreach ($customHeaderStringArray as $item) {
  6. $headers[] = $item;
  7. }
  8. $curl = curl_init($url);
  9. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  10. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  11. $result = curl_exec($curl);
  12. curl_close($curl);
  13. return $result;
  14. // var_dump($result);
  15. // var_dump ($result == 'true');
  16. }
  17. function CURLrequestPOST($url, $customHeaderStringArray='', $params = [])
  18. {
  19. $headers = array("Content-Type: application/json", "Accept:application/json");
  20. foreach ($customHeaderStringArray as $item) {
  21. $headers[] = $item;
  22. }
  23. $jsonEncoded = json_encode($params);
  24. $curl = curl_init();
  25. curl_setopt($curl, CURLOPT_URL, $url);
  26. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  27. curl_setopt($curl, CURLOPT_TIMEOUT, 60);
  28. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  29. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  30. curl_setopt($curl, CURLOPT_POST, 1);
  31. curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonEncoded);
  32. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  33. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  34. $result = curl_exec($curl);
  35. curl_close($curl);
  36. return $result;
  37. // var_dump($result);
  38. }