Reputation: 11
I want to get the real-time LPR Result from a Hikvision LPR Camera. I have the link from Hikvision ISAPI Document: /ISAPI/Traffic/channels/1/vehicleDetect/plates
I get the following error:
<?xml version="1.0" encoding="UTF-8"?>
<ResponseStatus version="2.0" xmlns="http://www.std-cgi.com/ver20/XMLSchema">
<requestURL>/ISAPI/Traffic/channels/1/vehicleDetect/plates</requestURL>
<statusCode>6</statusCode>
<statusString>Invalid XML Content</statusString>
<subStatusCode>badXmlContent</subStatusCode>
</ResponseStatus>
This link does not work whereas the link /ISAPI/Traffic/channels/1/vehicleDetect/ works. Please help me to solve this problem.
Upvotes: 1
Views: 3387
Reputation: 8104
The same problem when I ommited to post the input parameter, this following CURL command returns badXmlContent
:
curl --digest --user xxx:xxx
http://172.27.111.50/ISAPI/Traffic/channels/1/vehicleDetect/plates
But this one works ok:
curl --digest --user xxx:xxx
http://172.27.111.50/ISAPI/Traffic/channels/1/vehicleDetect/plates
-d "<AfterTime><picTime>2022-03-10T14:00:00Z</picTime></AfterTime>"
So the problem was omitting
-d "<AfterTime><picTime>2022-03-10T14:00:00Z</picTime></AfterTime>"
Upvotes: 0
Reputation: 11
Works:
$username = 'xxxxx';
$password = 'yyyyy';
$url = "https://xxx.xxx.xxx.xxx/ISAPI/Traffic/channels/1/vehicleDetect/plates";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch,CURLOPT_TIMEOUT, 30);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "<AfterTime version=\"2.0\"><picTime>2020-06-20T00:00:00Z</picTime></AfterTime>");
$first_response = curl_exec($ch);
$info = curl_getinfo($ch);
preg_match('/WWW-Authenticate: Digest (.*)/', $first_response, $matches);
if(!empty($matches))
{
$auth_header = $matches[1];
$auth_header_array = explode(',', $auth_header);
$parsed = array();
foreach ($auth_header_array as $pair)
{
$vals = explode('=', $pair);
$parsed[trim($vals[0])] = trim($vals[1], '" ');
}
$response_realm = (isset($parsed['realm'])) ? $parsed['realm'] : "";
$response_nonce = (isset($parsed['nonce'])) ? $parsed['nonce'] : "";
$response_opaque = (isset($parsed['opaque'])) ? $parsed['opaque'] : "";
$authenticate1 = md5($username.":".$response_realm.":".$password);
$authenticate2 = md5("POST:".$url);
$authenticate_response = md5($authenticate1.":".$response_nonce.":".$authenticate2);
$request = sprintf('Authorization: Digest username="%s", realm="%s", nonce="%s", opaque="%s", uri="%s", response="%s"',
$username, $response_realm, $response_nonce, $response_opaque, $url, $authenticate_response);
$request_header = array($request);
$request_header[] = 'Content-Type:application/json';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch,CURLOPT_TIMEOUT, 30);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, "<AfterTime version=\"2.0\"><picTime>2020-06-20T00:00:00Z</picTime></AfterTime>");
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_header);
$result['response']= curl_exec($ch);
print_r($result['response']);
}
Upvotes: 1
Reputation: 31
Invalid XML Content
HTTP Content "0" < grab the last20 plates
HTTP Methods IS "POST" !!! not GET the documentation is wrong, A get never send any data to the serveur ;), this is why you get an invalid xml format at input
Upvotes: 3