void StartCGI(const char *szURL,const char *szIP,int nPort,const char *szUser,const char *szPassword)
{
CURL *pCurl;
CURLcode res;
char szHost[128] = {0};
sprintf(szHost,"Host: %s",szIP);
pCurl = curl_easy_init();
if(pCurl!=NULL)
{
curl_easy_setopt(pCurl,CURLOPT_URL,szURL);
curl_easy_setopt(pCurl,CURLOPT_PORT,nPort);
curl_easy_setopt(pCurl,CURLOPT_FOLLOWLOCATION,1L);
curl_easy_setopt(pCurl,CURLOPT_HTTPGET,1L);
LONG nAuthArray[]= {0,CURLAUTH_BASIC,CURLAUTH_DIGEST,CURLAUTH_NEGOTIATE,CURLAUTH_NEGOTIATE};
curl_easy_setopt(pCurl,CURLOPT_HTTPAUTH, nAuthArray[0]);
curl_easy_setopt(pCurl,CURLOPT_USERNAME,szUser);
curl_easy_setopt(pCurl,CURLOPT_PASSWORD,szPassword);
struct curl_slist *pHeaders=NULL;
pHeaders = curl_slist_append(pHeaders, szHost);
pHeaders = curl_slist_append(pHeaders, "User-Agent: Mago");
char szCookies[128] = {0};
sprintf(szCookies,"Cookie: ptz_ctl_id=%s",szIP);
pHeaders = curl_slist_append(pHeaders, szCookies);
curl_easy_setopt(pCurl, CURLOPT_HTTPHEADER, pHeaders);
res = curl_easy_perform(pCurl);
if (res != CURLE_OK)
{
CHAR szError[1024] = {0};
strcpy(szError,curl_easy_strerror(res));
}
long retcode = 0;
res = curl_easy_getinfo(pCurl, CURLINFO_RESPONSE_CODE , &retcode);
if (retcode == 401)
{
long nAuthorize;
res = curl_easy_getinfo(pCurl, CURLINFO_HTTPAUTH_AVAIL, &nAuthorize);
if(!res)
{
if(!nAuthorize)
{
}
else
{
if (nAuthorize & CURLAUTH_DIGEST)
{
curl_easy_setopt(pCurl,CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
}
else if (nAuthorize & CURLAUTH_BASIC)
{
curl_easy_setopt(pCurl,CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
}
else if (nAuthorize & CURLAUTH_NEGOTIATE)
{
curl_easy_setopt(pCurl,CURLOPT_HTTPAUTH, CURLAUTH_NEGOTIATE);
}
else if (nAuthorize & CURLAUTH_NTLM)
{
curl_easy_setopt(pCurl,CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
}
res = curl_easy_perform(pCurl);
if (res != CURLE_OK)
{
CHAR szError[1024] = {0};
strcpy(szError,curl_easy_strerror(res));
}
}
}
}
curl_slist_free_all(pHeaders);
curl_easy_cleanup(pCurl);
}
}