/** * @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); }