Bonjour,
J'ai essyé un nombre incalculable de fois et je n'y arrives pas. pourtant si je passes par le navigateur avec les url, je peux le faire. Comment puis-je faire pour que cela fonctionne?
<?php
//authentification
$response = get_web_page("https://IP:5001/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=2&account=user&passwd=pwd&session=SurveillanceStation&format=sid");
//echo $response;
$resArr = array();
$resArr = ($response);
$resArr = json_decode($response,true);
//sid in the array
$sid=array();
$sid=$resArr[data];
echo $sid[sid];
//send Start record
$response = get_web_page("https://IP:5001/webapi/SurveillanceStation/extrecord.cgi?api=SYNO.SurveillanceStation.ExternalRecording&method=Record&version=1&cameraId=6&action=start&_sid=".$sid[sid]);
echo $response;
// send logoff
$response = get_web_page("https://IP:5001/webapi/auth.cgi?api=SYNO.API.Auth&method=Logout&version=2&session=SurveillanceStation&_sid=".$sid[sid]);
echo $response;
function get_web_page($url) {
$options = array (CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle compressed
CURLOPT_USERAGENT => "test", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10 ); // stop after 10 redirects
$ch = curl_init ( $url );
curl_setopt_array ( $ch, $options );
$content = curl_exec ( $ch );
$err = curl_errno ( $ch );
$errmsg = curl_error ( $ch );
$header = curl_getinfo ( $ch );
$httpCode = curl_getinfo ( $ch, CURLINFO_HTTP_CODE );
curl_close ( $ch );
$header ['errno'] = $err;
$header ['errmsg'] = $errmsg;
$header ['content'] = $content;
return $header ['content'];
}
?>