云台CGI

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); 
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值