微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。