kriak
Verified User
- Joined
- Jun 22, 2004
- Messages
- 26
Hi !
I just wrote that little function to call the API using https protocol.
And here is a POST example :
And a GET example :
Thank you for your feedback. It can also be integrated into the API call class since it do not seem to support SSL.
I just wrote that little function to call the API using https protocol.
PHP:
function DA_SSL_Request($user, $password, $request, $method='GET', $post_content='', $host='localhost', $port=2222)
{
$headers = '';
$headers[] = "Content-Type: application/x-www-form-urlencoded";
$headers[] = 'Content-length: '.strlen($post_content);
$headers[] = 'Authorization: Basic '.base64_encode("$user:$password");
$ch = curl_init();
$complete_url = 'https://'.$host.':'.$port;
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method.' '.$request.' HTTP/1.1');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL,$complete_url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15); // Time out sec.
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_content);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$answer = curl_exec($ch);
if( !$answer )
{
$answer['error'] = 1;
$answer['error_msg'] = "CONNECTION ERROR ".curl_errno($ch).": ".curl_error($ch);
}
else
{
parse_str($answer,$answer);
}
return $answer;
}
And here is a POST example :
PHP:
$user = 'admin';
$password = 'pass';
$request = "/CMD_API_SHOW_USERS";
$method = 'POST'; // GET or POST
$post_content = "reseller=admin";
$host = 'locahost';
$port = 2222;
$retval = DA_SSL_Request($user, $password, $request, $method, $post_content, $host, $port);
// Display results.
echo "<pre>";
print_r($retval);
echo "</pre>";
And a GET example :
PHP:
$user = 'admin';
$password = 'pass';
$request = "/CMD_API_SHOW_USER_DOMAINS?user=admin";
$method = 'GET'; // GET or POST
$post_content = "";
$host = 'locahost';
$port = 2222;
$retval = DA_SSL_Request($user, $password, $request, $method, $post_content, $host, $port);
// Display results.
echo "<pre>";
print_r($retval);
echo "</pre>";
Thank you for your feedback. It can also be integrated into the API call class since it do not seem to support SSL.
Last edited: