I am using a flask server and having Unity access it. Testing it in Postman (with platform:test) gives me ImmutableMultiDict([('platform', 'test')])
(result of request.form in Flask) which works. But when unity makes a post request (code provided), it gives me ImmutableMultiDict([])
. I'm not completely sure if this is a Unity or a Flask problem. Help is much appreciated.
IEnumerator PostRequest(string url)
{
WWWForm form = new WWWForm();
form.AddField("platform", "test");
UnityWebRequest uwr = UnityWebRequest.Post(url, form);
uwr.uploadHandler.contentType = "multipart/form-data";
yield return uwr.SendWebRequest();
if (uwr.isNetworkError)
{
Debug.Log("Error While Sending: " + uwr.error);
}
else
{
Debug.Log("Received: " + uwr.downloadHandler.text);
}
}
I have fixed the issue.
Unity formats its data wildly different from PostMan, and my Flask server couldn't read it. Instead of using request.form[key]
or request.data[key]
in Flask, I found request.form.getlist(key)
worked perfectly with both Postman's requests and Unity's.