CurlService.php 998 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php namespace Ixudra\Curl;
  2. class CurlService {
  3. public function get($url, $getParameters = array(), $isJson = false)
  4. {
  5. $curl = new Curl();
  6. $curl->setUrl( $url, $getParameters );
  7. return $this->send( $curl, $isJson );
  8. }
  9. public function post($url, $getParameters = array(), $postParameters, $isJson = false)
  10. {
  11. $curl = new Curl();
  12. $curl->setUrl( $url, $getParameters );
  13. $curl->setMethod( true );
  14. if( $isJson ) {
  15. $postParameters = json_encode($postParameters);
  16. $curl->addOption( 'HTTP_HEADER', array('Content-Type: application/json') );
  17. }
  18. $curl->setPostParameters( $postParameters );
  19. return $this->send( $curl, $isJson );
  20. }
  21. protected function send($curl, $isJson)
  22. {
  23. $response = $curl->send();
  24. if( $isJson ) {
  25. $response = json_decode($response);
  26. }
  27. return $response;
  28. }
  29. }