I have a problem in the code in which the API is not receiving the command for set_system_time, I don't know if it could be an error in the way of passing the parameters, follow the code used and the api documentation, in case anyone can help me in this case.
date.php (connects to the api, takes the session token and uses it for the second request)
<?php
$cookie="cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://192.168.5.23/login.fcgi');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{ \"login\": \"admin\", \"password\": \"senha\"}");
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Authorization: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$session1 = json_decode($result);
$sessao = $session1->{'session'};
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
//curl_close($ch);
///////////////
echo $sessao;
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, "http://192.168.5.23/set_system_time.fcgi?session=$sessao");
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_POSTFIELDS, "{ \"day\": \"1\", \"month\": \"2\", \"year\": \"2020\", \"hour\": \"21\", \"minute\": \"20\", \"second\": \"22\" }");
curl_setopt($ch1, CURLOPT_TIMEOUT, 60);
curl_setopt($ch1, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch1, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch1, CURLOPT_HTTPHEADER, $headers);
//$result = curl_exec($ch1);
curl_close($ch1);
?>
as the api shows that the information has to be passed, their example is in js, but I'm trying to do it using curl from PHP
$.ajax({
url: "/set_system_time.fcgi?session=" + session,
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({
day: 10,
month: 12,
year: 1983,
hour: 21,
minute: 30,
second: 00
})
});
I made the same request, taking the token and executing another api command, but this request didn't need to pass parameters, maybe the problem is in this part but I couldn't identify it.