- Home /
Help with unity form.Addfield
Hello you all
I'm really stuck with something i don't see why it is not working.
My goal is to send a POST variable from unity to a php file. The php file is working fine and when i submit a POST with an regular HTML form it is working. But not when i send it from unity.
Here is the code (i am using a example from unity itself)
using UnityEngine; using System.Collections; using UnityEngine.Networking;
public class FormSender : MonoBehaviour
{
public string discipline;
void Start()
{
StartCoroutine(Upload());
}
IEnumerator Upload()
{
WWWForm form = new WWWForm();
form.AddField("Discipline", discipline);
UnityWebRequest www = UnityWebRequest.Post("myworkingform.php", form);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log("Form upload complete!");
}
}
}
And in my php file i retrieve it like this: $discipline = $_POST['Discipline'];
(i don;t think it is in the php because with a regular HTML form it is working fine).
I really dont see what i am doing wrong.
Can someone help me??
Thnx
Your answer
Follow this Question
Related Questions
Log in on a website and get data 0 Answers
Upload files to a remote form using C# in Unity 2 Answers
REST API Response Error: 406 - not acceptable 1 Answer
WWWForm Question 2 Answers