c# 摘要身份验证在 Unity 中使用 SimpleJson 执行发布请求Ultimaker Jedi Api

问题描述

我正在尝试通过 Rest Api 远程控制 Ultimaker S5。我有 GET 请求和初始 POST 请求来让用户名和密码正常工作。我遇到的问题是,任何其他 POST 请求都需要摘要式身份验证。在 Python 中,这很容易解决,但是我花了 3 天时间尝试在 c# 中实现它,但没有成功。

这是我用于 POST 请求的代码,但是没有任何身份验证。

那么如何添加摘要验证但仍将我的 wwwForm 与我的参数一起发送?每一个提示和帮助都非常受欢迎!我刚开始接触编码!

IEnumerator GeneralPost(string URLaddition,string[] PostFieldsNames,string[] PostFieldobjects)
    {
        //string application = "UltiAR" ; 
        //string user = "Adrian" ; 
        
        var totalElements = PostFieldsNames.Count(); //number of post Fields
        WWWForm form = new WWWForm(); 

        string URL = baseURL+URLaddition; //puts together the whole URL
        Debug.Log("URL is "+ URL);

        for(int i = 0; i < totalElements; i++) //fills the WWWform
        {
            form.AddField(PostFieldsNames[i],PostFieldobjects[i]); 
        }
        
        using (UnityWebRequest PostJson = UnityWebRequest.Post(URL,form))
        {
            yield return PostJson.SendWebRequest();

            if (PostJson.isNetworkError || PostJson.isHttpError)
            {
                Debug.Log(PostJson.error);
            }
            else
            {
                Debug.Log("Form upload complete!");
            }
        
            JSONNode POSTJsonAnswer = JSON.Parse(PostJson.downloadHandler.text);

            if(URLaddition == "auth/request") //special case with text response
            {
                ID = POSTJsonAnswer["id"];
                KEY = POSTJsonAnswer["key"];

                Debug.Log("ID is:  " +ID);
                Debug.Log("Key is:  " +KEY);
            }
        }

这是我尝试执行 POST 时收到的响应标头

{
  "cache-control": "no-cache,no-store,must-revalidate","connection": "keep-alive","content-length": "38","content-type": "application/json","date": "Thu,04 Feb 2021 08:18:59 GMT","expires": "0","pragma": "no-cache","server": "Nginx/1.14.2","www-authenticate": "Digest realm=\"Jedi-API\",nonce=\"03c10f9b3d70e36510547dd9e1dde5bd\",qop=\"auth\""
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)