Ich hatte Probleme mit PHP die API anzusprechen.
Hier ist jetzt mein funktionierendes Script:
<pre><?php
ini_set('display_errors', 1);
$cookie = __DIR__ . DIRECTORY_SEPARATOR . "cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "
https://info.3cx.de:5001/api/login");
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 2);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array('Username' => 'admin', 'Password' => '********')));
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIELIST, "RELOAD");
$clist = curl_getinfo($ch, CURLINFO_COOKIELIST);
$serverLoginOutput = curl_exec($ch);
curl_close($ch);
if ($serverLoginOutput == "AuthSuccess") {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "
https://info.3cx.de:5001/api/ServiceList");
//curl_setopt($ch, CURLOPT_URL, "
https://info.3cx.de:5001/api/SystemStatus");
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 2);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
$serverSystemOutput = curl_exec($ch);
curl_close($ch);
$systemData = json_decode($serverSystemOutput);
var_dump($systemData);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "
https://info.3cx.de:5001/api/logout");
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 2);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
$serverSystemOutput = curl_exec($ch);
curl_close($ch);
$systemData = json_decode($serverSystemOutput);
}
?>
</pre>