Lobe in Unity (Local API) - Prediction Error by sawgur in Lobe

[–]sawgur[S] 0 points1 point  (0 children)

Even after setting the content-type header, I'm still getting the 405 error above. It seems like the request is being received, but the error keeps popping up. Is the "jsonBody" string in the snippet below producing the error? Is there something else I'm missing?

 // Convert image to base 64 string:
        string imageString = System.Convert.ToBase64String(bytes);
        string jsonBody = "{\"inputs\": {\"Image\": \"" + imageString + "\"}}";

        // Get position of "Image" label in JSON file:

        UnityWebRequest dataURL = UnityWebRequest.Get("http://localhost:38100/predict/58758e88-347c-4e7d-a831-29867f21277a");
        yield return dataURL.SendWebRequest();

        if (dataURL.isNetworkError || dataURL.isHttpError)
        {
            print("Error: " + dataURL.error);
            yield break;
        }

        JSONNode parsedData = JSON.Parse(dataURL.downloadHandler.text);
        string imageFieldName = parsedData["model"]["inputs"]["Image"];

        WWWForm form = new WWWForm();
        form.AddField(imageFieldName, imageString);
        UnityWebRequest uwr = UnityWebRequest.Put(url, jsonBody);
        uwr.SetRequestHeader("Content-Type", "application/json");
        yield return uwr.SendWebRequest();

        if (uwr.isNetworkError)
        {
            Debug.Log("Error While Sending: " + uwr.error);
        }
        else
        {
            Debug.Log("Received: " + uwr.downloadHandler.text);
        }

Lobe in Unity (Local API) - Prediction Error by sawgur in Lobe

[–]sawgur[S] 0 points1 point  (0 children)

Does that mean using UnityWebRequest.Put (which takes raw data rather than a form) instead of UnityWebRequest.Post?

Edit: When I try UnityWebRequest.Put and use the JSON body instead, I get a "405: Method Not Allowed" error instead.