Search Unity

Help Wanted UnityWebRequest Post submits empty/null $_POST

Discussion in 'Multiplayer' started by atalkingfish, Oct 1, 2020.

  1. atalkingfish

    atalkingfish

    Joined:
    Sep 17, 2018
    Posts:
    46
    I've been going through the documentation for submitting a form via UnityWebRequest.Post, and seemingly no matter what method I use, the values always run in empty on the server.

    Here is my IEnumerator that submits the web request

    Code (CSharp):
    1. IEnumerator Upload()
    2.     {
    3.         WWWForm form = new WWWForm();
    4.         form.AddField("action", "create-user");
    5.  
    6.         //url is filled in on my end, replacing with "--------" here
    7.         UnityWebRequest www = UnityWebRequest.Post("--------", form);
    8.         yield return www.SendWebRequest();
    9.  
    10.         if (www.isNetworkError || www.isHttpError)
    11.         {
    12.             Debug.Log(www.error);
    13.         }
    14.         else
    15.         {
    16.             Debug.Log(www.downloadHandler.text);
    17.         }
    18.     }
    It's basically just a carbon copy of every example of this I see, yet I cannot get $_POST or any variable of it to return anything. I did a var_dump of $_POST on the server and it returns an empty array. Is there a server setting or something of the sort that I'm missing?

    I've also tried using the IMultipartFormData and it does the same thing.

    It's also worth noting I have used GET and it works just fine, but I need the data to be sent through POST.
     
  2. atalkingfish

    atalkingfish

    Joined:
    Sep 17, 2018
    Posts:
    46
    I resolved the issue by using the IMultipartFormData method AND ensuring that the URL is set to https, two things I had tried previously but not together.
     
  3. rickcollette

    rickcollette

    Joined:
    Mar 17, 2013
    Posts:
    303
    Hi,

    I know im a bit late to this, and you seem to have solved your particular issue. I am curious what it is that you are working on? It seems to be a connected game of some kind - and if you are looking for an authorization/login, metric gathering, and analytics - Id like to chat about that. I am working on a system to provide just that; and would absolutely love some feedback around it. Maybe we can help each other?
     
unityunity