I’m trying to send a WWWForm object through UnityWebRequest.PUT. I’ve checked the documentation, and I know it only accepts byte[ ]. Is there a way to convert WWWForm to a byte array, so it can work?
Here’s my code:
private IEnumerator PutData(int id, int trashAmount, float time, float lat, float lon)
{
WWWForm form = new WWWForm();
form.AddField("trash_collected", trashAmount.ToString());
form.AddField("timespent", time.ToString());
form.AddField("latitude", lat.ToString());
form.AddField("longitude", lon.ToString());
var http = url + id.ToString();
UnityWebRequest put = UnityWebRequest.Put(http, form);
yield return put.SendWebRequest();
if (put.isNetworkError || put.isHttpError)
{
Debug.Log("Error " + put.error);
}
else
{
Debug.Log("Form upload complete!");
}
}