Skip to content
Permalink
Browse files

API POST method

  • Loading branch information...
sergejey committed Jul 10, 2019
1 parent 9f9982c commit 3bd8985aa85234bd09d4db36b090b15c7e3c6e7b
Showing with 29 additions and 73 deletions.
  1. +28 −54 lib/objects.class.php
  2. +1 −1 modules/application.class.php
  3. +0 −18 modules/objects/objects.class.php
@@ -962,70 +962,44 @@ function callMethodSafe($method_name, $params = 0)
function callAPI($api_url, $method = 'GET', $params = 0)
{
/*
$api_call_type = 'http';
if ($api_call_type == 'cmd') {
if (defined('PATH_TO_PHP'))
$phpPath = PATH_TO_PHP;
else
$phpPath = IsWindowsOS() ? '..\server\php\php.exe' : 'php';
$filename = dirname(__FILE__).'/../api.php';
$data=array();
$data['REQUEST_URI']=$api_url;
$data['REQUEST_METHOD']=$method;
if (is_array($params)) {
foreach($params as $k=>$v) {
$data[$k]=$v;
}
}
$cmdParams = addcslashes(serialize(json_encode($data)), '"');
$command = $phpPath . ' -q ' . $filename . ' --params "' . $cmdParams . '"';
if (!IsWindowsOS()) {
$command='exec '.$command;
}
$descriptorSpec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w')
);
$new_proc = proc_open($command, $descriptorSpec, $pipes);
stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);
return $new_proc;
}
*/
//if ($api_call_type == 'http') {
startMeasure('callAPI');
$url = BASE_URL . $api_url;
if (!is_array($params)) {
$params = array();
}
$params['no_session']=1;
$url .= '?' . http_build_query($params);
$url = str_replace('/api/', '/api.php/', $url);
$method=strtoupper($method);
global $api_ch;
if (!isset($api_ch)) {
$api_ch = curl_init();
curl_setopt($api_ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0');
curl_setopt($api_ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($api_ch, CURLOPT_CONNECTTIMEOUT, 10); // connection timeout
curl_setopt($api_ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($api_ch, CURLOPT_TIMEOUT, 45); // operation timeout 45 seconds
curl_setopt($api_ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($api_ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($api_ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($api_ch, CURLOPT_TIMEOUT_MS, 50);
}
if ($method == 'GET') {
//DebMes("API query: ".$url,'api_query');
//getURLBackground($url);
global $api_ch;
if (!isset($api_ch)) {
$api_ch = curl_init();
curl_setopt($api_ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0');
curl_setopt($api_ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($api_ch, CURLOPT_CONNECTTIMEOUT, 10); // connection timeout
curl_setopt($api_ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($api_ch, CURLOPT_TIMEOUT, 45); // operation timeout 45 seconds
curl_setopt($api_ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($api_ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($api_ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($api_ch, CURLOPT_TIMEOUT_MS, 50);
}
curl_setopt($api_ch, CURLOPT_URL, $url);
curl_exec($api_ch);
$url .= '?' . http_build_query($params);
curl_setopt($api_ch, CURLOPT_POSTFIELDS, 0);
curl_setopt($api_ch, CURLOPT_POST, 0);
} elseif ($method == 'POST') {
curl_setopt($api_ch, CURLOPT_POST, 1);
curl_setopt($api_ch, CURLOPT_POSTFIELDS, $params);
}
$url = str_replace('/api/', '/api.php/', $url);
curl_setopt($api_ch, CURLOPT_URL, $url);
curl_exec($api_ch);
endMeasure('callAPI');
//}
return true;
}
@@ -396,7 +396,7 @@ function sortFiles($a, $b) {
$code.=$obj."->getParams();\n";
$code.=$obj."->ajax=1;\n";
$code.=$obj."->run();\n";
StartMeasure("module_".$this->action);
startMeasure("module_".$this->action);
eval($code);
endMeasure("module_".$this->action);
@@ -510,24 +510,6 @@ function callMethodSafe($name, $params = 0)
}
$call_stack[] = $current_call;
/*
$data=array(
'object'=>$this->object_title,
'op'=>'m',
'm'=>$name,
'm_c_s'=>$call_stack
);
if (session_id()) {
$data[session_name()]=session_id();
}
$url=BASE_URL.'/objects/?'.http_build_query($data);
if (is_array($params)) {
foreach($params as $k=>$v) {
$url.='&'.$k.'='.urlencode($v);
}
}
$result = getURLBackground($url,0);
*/
if (!is_array($params)) {
$params = array();
}

0 comments on commit 3bd8985

Please sign in to comment.
You can’t perform that action at this time.