CPPRESTSDK fails to retrieve results when request api/iomonitor.
AnsweredThis is the person who asked a question about getting the switch state of the IO device last time.
When I request the api/iomonitor API using CPPRESTSDK, I get a 200 OK response,
When I run the extract_json() method and try to get the results, I get no response from the method.
Below is a sample code.
pplx::task<json::value> getIODeviceStatus(const std::string& inUrl)
{
const std::string sUrl = inUrl;
return pplx::create_task([sUrl]
{
// setup connection config
web::http::client::http_client_config conf;
conf.set_timeout((std::chrono::microseconds)10000);
utility::string_t sUtf16 = utility::conversions::utf8_to_utf16(sUrl);
sUtf16 = uri::encode_uri(sUtf16, uri::components::component::query);
web::http::client::http_client client(sUtf16, conf);
web::http::http_request cRequest(methods::GET);
return client.request(cRequest);
}).then([sUrl](http_response cResponse)
{
if (cResponse.status_code() == status_codes::OK)
{
::printf("[GET] %s success. \n", sUrl.c_str());
http_headers cHeader = cResponse.headers();
}
else
{
::printf("[E][GET] %s failed. status=%d \n", sUrl.c_str(), cResponse.status_code());
}
return cResponse.extract_json(true);
});
}
Run this method like this:
getIODeviceStatus("http://[NxWitness VMS Server]/api/iomonitor?cameraid=[iodeviceid]").wait();
When I run this code I get no response when I run cResponse.extract_json(true) method call.
Is this related to the fact that the api/iomonitor API is a regular monitoring API?
-
Hello,
The /api/iomonitor API should be used in a specific way.
You should establish HTTPS connect and keep it open. The Server will periodically send updated IO status over this HTTPS connection.
Hope this helps in refactoring your code.
0 -
thank you for answering!
That seems to be the only way.
I will re-implement it like the answer you gave me.
0
Please sign in to leave a comment.
Comments
2 comments