場景
在安迅士攝像機網頁上,配置系統選項,HTTP/RTSP Password Settings 中, 選擇UnEncrypted only。獲取設備的雲臺狀態信息curl
代碼
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);
}
ide