I am trying to remote control the Ultimaker S5 via Rest Api. I ve got GET-requests and the initial POST-request to get the username and password working just fine. The problem I am having is, that any other POST-requests require Digest Authentication. In Python this is quite easy to solve, however I spent the last 3 Days trying to implement it in c# with no sucsess.
This is the code that I use for my POST-requests, however this is without any authentication.
So how can I add the digest authenticaion but still send my wwwForm with my parameters? Every hint and help is highly appriciated! I am just starting to get into coding!
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);
}
}
This is the respone header that I am recieving if I try to do a 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""
}
question from:
https://stackoverflow.com/questions/66061386/c-sharp-digest-authentication-to-do-a-post-request-with-simplejson-in-unity-ult 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…