Exemplo n.º 1
0
 /**
  * Get the response body as string
  *
  * This method returns the body of the HTTP response (the content), as it
  * should be in it's readable version - that is, after decoding it (if it
  * was decoded), deflating it (if it was gzip compressed), etc.
  *
  * If you want to get the raw body (as transfered on wire) use
  * $this->getRawBody() instead.
  *
  * @return string
  */
 public function getBody()
 {
     if ($this->stream != null) {
         $this->readStream();
     }
     return parent::getBody();
 }
Exemplo n.º 2
0
 /**
  * @desc curl http request
  * @param type $url
  * @param type $param(POST parameter)
  * @param type $header (Request header)
  * @return string     /
  */
 public static function requestCurl($url, $param = array(), $header = array())
 {
     if ($url != '') {
         try {
             $client = new EHttpClient($url, array('maxredirects' => 0, 'timeout' => 60000));
             $client->setMethod(EHttpClient::POST);
             if (!empty($header)) {
                 $client->setHeaders($header);
             }
             if (!empty($param)) {
                 $client->setParameterPost($param);
             }
             //$client->setRawData($tokenJsonStr,'json');
             $response = $client->request();
         } catch (Exception $e) {
             $response = new EHttpResponse('Client side exception', array(), "", '1.1', PHP_EOL . 'Exception: ' . $e->getMessage() . PHP_EOL);
         }
         //App::pr($response,9);
         if ($response->getStatus() == '200') {
             return $response->getBody();
         } else {
             if ($response->getStatus() == '207') {
                 $resp = $response->getBody();
                 //$resp = App::objtoarray(json_decode($resp));
                 return $resp;
             } else {
                 if ($response->getStatus() == '201') {
                     return '1';
                     ## if status 201, than insertion on db through api is successfull.
                 } else {
                     //App::pr($response,8);
                     return 'error';
                 }
             }
         }
     }
 }
             $status = '{"status":"-1"}';
             echo $status;
             die;
         }
     }
 }
 public function doPost($url, $config = NULL, $params = NULL, $localFile = NULL, $fileUploadFormName = NULL, $methodType = "")
 {
     try {
         $client = new EHttpClient($url);
         if (isset($methodType) && $methodType != "") {
             $client->setMethod(EHttpClient::POST);
         } else {
             $client->setMethod(EHttpClient::GET);
         }
         $client->setParameterPost($params);
         if ($localFile) {
             // Upload item to database
             $client->setFileUpload($localFile, $fileUploadFormName);
         }