Onvif Digest 驗證方式代碼編寫

首先將Gsoap plugin目錄下的md5evp.h, md5evp.c, httpda.h,httpda.c,threads.h,threads.c文件加入到項目工程中

在實際編寫代碼的cpp文件中引入頭文件 #include “httpda.h”

在編譯的過程中會提示soap_memcpy 和 SOAP_SNPRINTF的相關錯誤,只需要在gsoap下找到對應的聲明添加到 stdsoap2.h即可

在使用WS-UsernameToken方式進行權限驗證時,如果驗證不通過,那麼將會返回400錯誤。 在使用Digest方式進行權限驗證時,如果驗證不通過,那麼將返回401錯誤。

soap_call___ns_method(&soap, ...);
if (soap.status == 400)
    {
        soap_register_plugin(&soap, http_da);
        soap.userid = "username";
        soap.passwd = "password";
        soap_call___ns_method(&soap, ...);
        if (soap.status == 401)
        {
            struct http_da_info info; // to store userid and passwd
            //soap.authrealm在驗證失敗從服務器返回
            http_da_save(&soap, &info, soap.authrealm, "username", "password");
            soap_call___ns_method(&soap, ...);
            http_da_restore(&soap, &info);
            http_da_release(&soap, &info);
        }
    }

大多設備支持ws-usernameToken方式,少些設備不支持,當權限驗證存在衝突時則需要兼容處理。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章