I am trying to write to a Microsoft API from Unity, but I get a 500 internal server error
whenever I try to POST
. I am able to use the same script to post to other APIs, just not this PowerBI Microsoft API. Here is the code I am using:
string jsonData = JsonUtility.ToJson("[" + player + "]");
UnityEngine.Debug.Log(jsonData);
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonData);
using (UnityWebRequest www = UnityWebRequest.PostWwwForm(URL, jsonData))
{
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
UnityEngine.Debug.Log(www.error);
}
else
{
UnityEngine.Debug.Log("Form upload complete!");
}
}
I met with Microsoft support about this and all they can tell me is that the variable bodyRaw with the bytes is what I should be sending to the API, but the Unity WebRequest only allows a string as input.
I tried this but got the same 500 error:
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonData);
string data = System.Text.Encoding.Default.GetString(bodyRaw);
using (UnityWebRequest www = UnityWebRequest.PostWwwForm(URL, data))