K3Curl.Class.php 937 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: ASUS
  5. * Date: 2018/7/18
  6. * Time: 10:53
  7. */
  8. namespace Jobs\Model\Test;
  9. class K3Curl
  10. {
  11. public static function MyCurlPost($url, $post_content, $cookie_jar, $isLogin)
  12. {
  13. $ch = curl_init($url);
  14. $this_header = array(
  15. 'Content-Type: application/json',
  16. 'Content-Length: ' . strlen($post_content)
  17. );
  18. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  19. curl_setopt($ch, CURLOPT_HTTPHEADER, $this_header);
  20. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_content);
  21. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  22. if ($isLogin) {
  23. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
  24. } else {
  25. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
  26. }
  27. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  28. $result = curl_exec($ch);
  29. curl_close($ch);
  30. return $result;
  31. }
  32. }