12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php namespace Ixudra\Curl;
- class CurlService {
- public function get($url, $getParameters = array(), $isJson = false)
- {
- $curl = new Curl();
- $curl->setUrl( $url, $getParameters );
- return $this->send( $curl, $isJson );
- }
- public function post($url, $getParameters = array(), $postParameters, $isJson = false)
- {
- $curl = new Curl();
- $curl->setUrl( $url, $getParameters );
- $curl->setMethod( true );
- if( $isJson ) {
- $postParameters = json_encode($postParameters);
- $curl->addOption( 'HTTP_HEADER', array('Content-Type: application/json') );
- }
- $curl->setPostParameters( $postParameters );
- return $this->send( $curl, $isJson );
- }
- protected function send($curl, $isJson)
- {
- $response = $curl->send();
- if( $isJson ) {
- $response = json_decode($response);
- }
- return $response;
- }
- }
|