Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Question UnityWebRequest Post submits empty/null $_POST

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

  1. atalkingfish


    Sep 17, 2018
    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");
    6.         //url is filled in on my end, replacing with "--------" here
    7.         UnityWebRequest www = UnityWebRequest.Post("--------", form);
    8.         yield return www.SendWebRequest();
    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


    Sep 17, 2018
    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


    Mar 17, 2013

    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?