Answer the question
In order to leave comments, you need to log in
How should I authenticate with curl on Digest (Dahua API)?
I periodically (every ~50 iterations) have an error when getting a list of new videos on the ip camera. I'm not sure, but maybe this is due to the fact that I crookedly authorize. The API says this:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="XXXXXX"
Authorization: Basic VXZVXZ
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Digest realm="DH_00408CA5EA04",
nonce="000562fdY631973ef04f77a3ede7c1832ff48720ef95ad", stale=FALSE, qop="auth"
Authorization: Digest username="admin", realm="DH_00408CA5EA04", nc=00000001, cnonce="0a4f113b",
qop="auth", nonce="000562fdY631973ef04f77a3ede7c1832ff48720ef95ad",
uri="/cgi-bin/magicBox.cgi?action=getLanguageCaps", response="65002de02df697e946b750590b44f8bf"
function reqCam($url, $code = false) {
$ch = curl_init($url);
curl_setopt_array($ch, [CURLOPT_USERPWD => "admin:password", CURLOPT_CONNECTTIMEOUT => 15, CURLOPT_RETURNTRANSFER => 1, CURLOPT_HTTPAUTH=>CURLAUTH_ANY]);
$res = curl_exec($ch);
if ($code) return curl_getinfo($ch, CURLINFO_HTTP_CODE);
return $res;
}
# получаю task
$firstreq = reqCam("http://admin:[email protected]/cgi-bin/mediaFileFind.cgi?action=factory.create"); // result=2128862112
$id = explode("=",trim($firstreq));
# делаю запрос на период времени
$reqStat = trim(reqCam("http://admin:[email protected]/cgi-bin/mediaFileFind.cgi?action=findFile&object={$id[1]}&condition.Channel=1&condition.StartTime=$start&condition.EndTime=$end&condition.Types[0]=dav"));
# получаю список файлов
$secreq = reqCam("http://admin:[email protected]/cgi-bin/mediaFileFind.cgi?action=findNextFile&object={$id[1]}&count=100");
# далее я уже работаю со списком файлов
Answer the question
In order to leave comments, you need to log in
At the first request, you receive a token in the headers, and they need to log in on subsequent requests
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question