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. Dismiss Notice

UnityWebRequest Post is empty on WebGL build but works fine in editor

Discussion in 'Editor & General Support' started by quantsolutions, Mar 29, 2021.

  1. quantsolutions

    quantsolutions

    Joined:
    Oct 20, 2020
    Posts:
    4
    EDIT: I solved the issue here. It was a server side problem and unrelated to Unity. I needed to update .htaccess file to allow for Post from same domain.





    Hello, I am using a UnityWebRequest Post to send information to a PHP file on my server. Everything works fine in the editor, but when I Build the project and put it online the Post form is empty.

    Can anyone point me in the right direction with this? I've looked through several posts/websites that offer many of the solutions I'm already using or their solutions didn't work.

    Here's what the code looks like:

    Code (CSharp):
    1.  
    2.         string loginURL = "https://www.mywebsiteurl.com/file.php
    3.  
    4.        // Create and populate wwwform with login information
    5.        WWWForm form = new WWWForm();
    6.        form.AddField("password", password);
    7.        form.AddField("email", email);
    8.  
    9.        // Create webrequest and post login information
    10.        UnityWebRequest www = UnityWebRequest.Post(loginURL, form);
    11.  
    12.        yield return www.SendWebRequest();
    13.  
    14.        // Check the result and return message
    15.        if (www.error != null) {
    16.            Debug.Log("Network Error.");
    17.            displayMessage.Display("Network Error.");
    18.        }
    19.        else {
    20.            returnMessage = ParseLoginFeedback(loginFeedback);
    21.            // Display message in debug
    22.            Debug.Log(returnMessage);
    23.            // Show user the display message
    24.            displayMessage.Display(returnMessage);
    25.        }
     
    Last edited: Mar 29, 2021
  2. SharrTZaw

    SharrTZaw

    Joined:
    Mar 30, 2019
    Posts:
    13
    Hello, I have the same problem. My http request work on editor but when I build WebGL, It returns empty When I test on localhost, cloud server and itch.io. Can you show me How to update .htaccess file to allow post.