项目
在安迅士摄像机网页上,配置系统选项,HTTP/RTSP Password Settings 中, 选择Encrypted only。获取设备的云台状态信息,使用的是摘要认证
例子
void CAnXunShiConn::TestlibCurlHTTPDegistAuth()
{
CURL *pCurlHandle = curl_easy_init();
curl_easy_setopt(pCurlHandle, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(pCurlHandle, CURLOPT_URL, "http://192.168.18.84/axis-cgi/com/ptz.cgi?camera=1&query=position");
curl_easy_setopt(pCurlHandle, CURLOPT_USERPWD, "root:admin12345");
curl_easy_setopt(pCurlHandle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_easy_setopt(pCurlHandle, CURLOPT_WRITEFUNCTION, WriteResponseBody);//设置回调函数
//curl_easy_setopt(pCurlHandle, CURLOPT_HEADER, 1);//保存HTTP头部信息到strResponseData
curl_easy_setopt(pCurlHandle, CURLOPT_WRITEDATA, &strResponseData);//设置回调函数的参数,获取反馈信息
curl_easy_setopt(pCurlHandle, CURLOPT_TIMEOUT, 15);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
curl_easy_setopt(pCurlHandle, CURLOPT_MAXREDIRS, 1);//查找次数,防止查找太深
curl_easy_setopt(pCurlHandle, CURLOPT_CONNECTTIMEOUT, 5);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
CURLcode nRet = curl_easy_perform(pCurlHandle);
if (0 == nRet)
{
std::cout << strResponseData << std::endl;
}
curl_easy_cleanup(pCurlHandle);
}
基础知识
◆ 摘要认证 digest authentication ← HTTP1.1提出的基本认证的替代方法
服务器端以nonce进行质询,客户端以用户名,密码,nonce,HTTP方法,请求的URI等信息为基础产生的response信息进行认证的方式。
※ 不包含密码的明文传递
摘要认证步骤:
1. 客户端访问一个受http摘要认证保护的资源。
2. 服务器返回401状态以及nonce等信息,要求客户端进行认证。
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Digest
realm="testrealm@host.com",
qo