例子
        在安迅士摄像机网页上,配置系统选项,HTTP/RTSP Password Settings 中, 选择UnEncrypted only。获取设备的云台状态信息


代码

void CAnXunShiConn::TestlibCurlHTTPBasicAuth()
{
 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_BASIC);
 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);
}