HTTPRequester.php 1.0 KB

12345678910111213141516171819202122232425262728
  1. <?php
  2. class HTTPRequester {
  3. /**
  4. * @description Make HTTP-POST call
  5. * @param $url
  6. * @param array $params
  7. * @param $aheader \http\Header
  8. * @return HTTP-Response body or an empty string if the request fails or is empty
  9. */
  10. public static function HTTPPost($url, array $params, array $aheader) {
  11. $query = http_build_query($params);
  12. $ch = curl_init();
  13. if (stripos($url, "https://") !== FALSE) {
  14. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  15. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  16. curl_setopt($ch, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
  17. }
  18. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  19. curl_setopt($ch, CURLOPT_HTTPHEADER, $aheader);
  20. curl_setopt($ch, CURLOPT_URL, $url);
  21. curl_setopt($ch, CURLOPT_POST, true);
  22. curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
  23. $response = curl_exec($ch);
  24. curl_close($ch);
  25. return $response;
  26. }
  27. }