Get the Real-time lpr result from hikvision camera - postman

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.

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

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']);
}

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>"

Related

Why request work in postman but does not work in curl (C++ libcurl)

I'm trying download comments from YouTube through private api but for some reason request to api does not work in curl. It should return JSON with information about comments under video but to me it return nothing. Literally nothing. In postman with same parameters and headers all work perfectly. I think that i'm not correctly use curl but i does not know where i wrong.
My downloader code:
QMap<QString, QString> commentsChunk = {
{"Accept", "*/*"},
{"Host", "www.youtube.com"},
{"Content-Type", "application/x-www-form-urlencoded"},
{"Origin", "https://www.youtube.com"},
{"DNT", "1"},
{"Pragma", "no-cache"},
{"Cache-control", "no-cache"},
{"TE", "Trailers"},
};
QString dir = KTools::Options::configPath + "/tmp";
cc->setErrFile(dir, "errfile.txt");
cc->currHeaderMode = KTools::Enums::Curl::HeaderMode::None;
cc->currCookieMode = KTools::Enums::Curl::CookieMode::GetAllTimes;
cc->cookieFileName = "cookieYoutube.txt";
cc->cookiePath = KTools::Options::configPath;
cc->setOptions();
QByteArray data = cc->request(params.value("url").toString() + "/videos");
KTools::HtmlAst::Object htmlObj = KTools::HtmlAst::Object();
htmlObj.makeAst(data);
QString xsrfToken = QUrl::toPercentEncoding(htmlObj.arrsAndObjs.objects[0].value("XSRF_TOKEN").toString());;
commentsChunk["X-YouTube-Client-Version"] = htmlObj.arrsAndObjs.objects[0].value("INNERTUBE_CONTEXT_CLIENT_VERSION").toString();
commentsChunk["X-YouTube-Client-Name"] = htmlObj.arrsAndObjs.objects[0].value("INNERTUBE_CONTEXT_CLIENT_NAME").toVariant().toString();
QJsonArray videosInfo = htmlObj.arrsAndObjs.objects[3].value("contents").toObject().value("twoColumnBrowseResultsRenderer").toObject().value("tabs").toArray()[1].toObject().value("tabRenderer").toObject().value("content").toObject().value("sectionListRenderer").toObject().value("contents").toArray()[0].toObject().value("itemSectionRenderer").toObject().value("contents").toArray()[0].toObject().value("gridRenderer").toObject().value("items").toArray(); // line 45 "items":[...]
QVector<QString> videosId;
for (int i = 0; i < videosInfo.size(); i++)
{
videosId.append(videosInfo[i].toObject().value("gridVideoRenderer").toObject().value("videoId").toString());
}
data = cc->request("https://www.youtube.com/watch?v=" + videosId[1]);
htmlObj = KTools::HtmlAst::Object();
htmlObj.makeAst(data);
QJsonArray continuations = htmlObj.arrsAndObjs.objects[5].value("contents").toObject().value("twoColumnWatchNextResults").toObject().value("secondaryResults").toObject().value("secondaryResults").toObject().value("continuations").toArray();
QVector<QJsonObject> commentsJsons;
cc->restartSession();
cc->setRequestType(KTools::Enums::Curl::RequestType::Post);
cc->currHeaderMode = KTools::Enums::Curl::HeaderMode::Custom;
QVector<QVector<QVector<QString>>> regexResult;
KTools::ExForString::executeRegex(data, {{"([^\"]+___________[^\"]+)\",\"[^\"]+\":\"([^\"]+)"}}, regexResult);
cc->setHeader(commentsChunk);
cc->setOptions();
QString tmp = QUrl::toPercentEncoding(regexResult[0][0][1]);
QString tmp2 = QUrl::toPercentEncoding(regexResult[0][0][2]);
cc->currPostParam = "session_token=" + xsrfToken;
data = cc->request("https://www.youtube.com/comment_service_ajax?action_get_comments=1&pbj=1&ctoken=" + tmp + "&continuation=" + tmp + "&itct=" + tmp2);
KTools::File::writeFile((tmp + "\n" + tmp2 + "\n" + cc->currPostParam).toUtf8(), dir, "requestParams.txt");
cc->unsetErrFile();
QString nope;
My curl wrapper code:
Header file: https://pastebin.com/beg1MYgG
Implementation file: https://pastebin.com/Dv4i823P
Curl log: https://pastebin.com/xXnsQEqY
Update: Thanks to suggestion in comment i locate my problem. For some reason function std::string::c_str() work incorrectly, in other words gives random characters. How can i fix it?
In the end it's just been UB.
if (currRequestType == KTools::Enums::Curl::RequestType::Post)
{
curl_easy_setopt(gCurlHandle, CURLOPT_POSTFIELDS, currPostParam.toStdString().c_str());
curl_easy_setopt(gCurlHandle, CURLOPT_POSTFIELDSIZE, currPostParam.size());
}
Curl store not string but reference to string. But temporary string returned bu c_str() destroys in the end of if statement.

Trying to publish to my wall, getting "Insufficient permission" error

I am using the following code post to my timeline. I am getting an error which is shown at the end of this post. Any ideas?
<?php
......
$request = 'https://graph.facebook.com/oauth/access_token';
$grant_type = 'client_credentials';
$client_id = '1504901xxxxxxxx'; //FaceBook Developer App_id LIVE
$client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; //Facebook Developer Api_secret LIVE
$postargs = 'grant_type=' . urlencode($grant_type) . '&client_id=' . $client_id . '&client_secret=' . $client_secret;
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
preg_match('/access_token=(.*)/', $response, $match);
curl_close($session);
$access_token = trim($match[1]);
$Application = 'WTSO';
$User = '1504901xxxxxxxx'; /*this is the user id*/
$target_id = '1647886xxxxxxxx';
$api_url = 'https://api.facebook.com/method/stream.publish?';
$server_loc = 'https://wtso.com';
$logo = new stdClass();
$attachment = new stdClass();
$logo->type = 'image';
$logo->src = 'http://admin.wtso.com' . '/images/' . (($new_products['image_name']) ? $new_products['image_name'] : 'xx1235.jpg');
$logo->href = $facebook_bitly;
$attachment->name = ' '; //'WTSO Product Notification';
$attachment->caption = (!empty($new_products['products_short_description'])) ? substr(strip_tags($new_products['products_short_description']), 0, 900) : $facebookText;
$attachment->description = ' ';
$attachment->href = $facebook_bitly;
$attachment->media = array($logo);
$message = (!empty($facebookText)) ? strip_tags($facebookText) : $new_products['products_name'];
$postargs2 = 'message=' . urlencode($message) . '&attachment=' . urlencode(json_encode($attachment)) . '&target_id=' . urlencode($target_id) . '&access_token=' . urlencode($access_token) . '&method=stream.publish';
$request2 = $api_url . $postargs2;
//Initiating a 2nd Curl instance
$session2 = curl_init($request2);
curl_setopt($session2, CURLOPT_HEADER, false);
curl_setopt($session2, CURLOPT_RETURNTRANSFER, true);
$response2 = curl_exec($session2);
curl_close($session2);
?>
I am getting this error from Facebook in $response2
<error_code>200</error_code>
<error_msg>Insufficient permission to post to target on behalf of the viewer</error_msg>

Get Title, URL, Description and insert it to database

I'm new here and need help to fix my code.
I'm trying to make a code using DomXPath to grab title, url and description from bing search and then save it to my DB.
Here is the code :
<?php
$s="something-words";
$keywords = strstr($s, '-') ? str_replace('-', '+', $s) : $s;
$html5 = new DOMDocument();
#$html5->loadHtmlFile('http://www.bing.com/search?q='.$keywords.'&go=&qs=bs&filt=all');
$xpath5 = new DOMXPath($html5);
$nodes = $xpath5->query('//div[#class="sb_tlst"]/h3');
$nodes = $xpath5->query('//div[#class="sb_meta"]/cite');
$nodes = $xpath5->query('//div[#id="results"]/ul[#id="wg0"]/li/div/div/p');
$data = array();
$data2 = array();
$data3 = array();
$i = 0;
foreach ($nodes as $node) {
$data = $node->textContent;
$i++;
// insert table urlgrab
mysql_query( "INSERT INTO urlgrab(title) Values ('$data')");
$data2 = $node->textContent;
$i++;
// update table urlgrab
dbConnect();
mysql_query( "UPDATE urlgrab SET url='$data2' WHERE title='$data'" );
$data3 = $node->textContent;
$i++;
// update table urlgrab
dbConnect();
mysql_query( "UPDATE urlgrab SET description='$data3' WHERE title='$data'" );
}
?>
the problem is I get same results in database for title,url,description. How to fix this code to get all data title,url and description save to my DB?
As you have messed up you code so it's hard to identified. But by assumption I have generated below code which should work for you.
$titles = $xpath5->query('//div[#class="sb_tlst"]/h3');
$urls = $xpath5->query('//div[#class="sb_meta"]/cite');
$descriptions = $xpath5->query('//div[#id="results"]/ul[#id="wg0"]/li/div/div/p');
$arrTitle = array();
foreach($titles as $title){
$arrTitle[] = $title->textContent;
}
$arrUrl = array();
foreach($urls as $url){
$arrUrl[] = $url->textContent;
}
$arrDescription = array();
foreach($descriptions as $description){
$arrDescription[] = $description->textContent;
}
$i = 0;
dbConnect();
foreach ($i=0; $i < count($arrTitle); $i++) {
$title = $arrTitle[$i];
$url = $arrUrl[$i];
$description = $arrDescription[$i];
mysql_query( "INSERT INTO urlgrab(`title`, `url`, `description`) Values ('$title', '$url', '$description')");
}
*Remove $i++; in loop and then run. Actually we're doing $i++ in for loop * And that will solve your issue.

Example code of FBML App that uses signed_request?

We did not know that Oct 1 is also deadline for signed_request.
Does anyone have example code to do signed_request for FBML apps?
We are trying to beat the deadline on Oct 1. Thanks!
The signed_request documentation shows how to do it in PHP. It's pretty easy to do in any language.
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}

PowerShell - Exception New-WebServiceProxy SOAP

When I execute my code, the following exception was thrown (German):
Ausnahme beim Aufrufen von "GetListItems" mit 7 Argument(en):
"Exception of type
'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."
Is it possible to get more details about the Soap Server Exception?
My code:
$url = "http://mysharepoint.de/websites/test/"
$docBib = "TestDocLib"
$sitesWS = New-WebServiceProxy ($url + "_vti_bin/Lists.asmx") -UseDefaultCredential
$sitesWS.Proxy = New-Object System.Net.WebProxy("")
$xmlDoc = New-Object System.Xml.XmlDocument
$xmlDoc.LoadXml("<Document><Query /><ViewFields /><QueryOptions /></Document>")
$queryNode = $xmlDoc.SelectSingleNode("//Query")
$viewFieldsNode = $xmlDoc.SelectSingleNode("//ViewFields")
$queryOptionsNode = $xmlDoc.SelectSingleNode("//QueryOptions")
$queryNode.InnerXml = "<Where></Where>"
$sitesWS.GetList("test")
$result = $sitesWS.GetListItems($docBib, $null, $queryNode, $viewFieldsNode, $null, $queryOptionsNode, $null)
I've struggled with managing Sharepoint via web services as well. So I can tell how picky these can be with their arguments. This is how I set the GetListItems call up - and got it working:
$xmlDoc = new-object System.Xml.XmlDocument
$viewFields = $xmlDoc.CreateElement("ViewFields")
$queryOptions = $xmlDoc.CreateElement("QueryOptions")
$queryOptionsString = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><DateInUtc>TRUE</DateInUtc><ViewAttributes Scope='RecursiveAll' />"
$queryOptions.set_innerXML($queryOptionsString)
$query = $xmlDoc.CreateElement("Query")
$sitesWS = $service.GetListItems($docBib, "", $query, $viewFields, "", $queryOptions, "")
The trick, I think is that I create XML elements for each of $viewFields,$queryOptions and $query (but both viewFields and query can be empty except for their 'root' tags).