Hi Guys, I am relatively new to unity and i have been extensively doing research and not really finding anything helpful, I’ve been trying to find a way to get a Unity Script to HTTP Post the values like a Username and Password to a Web API so that MVC can do the logic and processing of SQL commands. So the problem for me is to get the values from unity into MVC so that i can start doing validation checks. I have been experimenting with GET and POST but i must be doing something wrong as its not getting a return value from MVC just a blank. Does anyone have a method of sending values from unity to MVC and then doing verification and validation with the values received and then sending a token or something back to unity for display or something?
This is the Unity Code:
public void Start()
{
StartCoroutine(GetLoginResponse());
}
IEnumerator GetLoginResponse()
{
userName = Username.GetComponent<Text>().text;
userPass = UserPass.GetComponent<Text>().text;
WWWForm form = new WWWForm();
form.AddField("Username", userName);
form.AddField("UserPass", userPass);
string url = "https://localhost:44359/api/values/";
UnityWebRequest www = UnityWebRequest.Post(url, form);
yield return www.SendWebRequest();
if (www.isNetworkError)
{
Debug.Log(www.error);
}
else
{
if (www.isDone)
{
string jsonResult = System.Text.Encoding.UTF8.GetString(www.downloadHandler.data);
usernameOutput.GetComponent<Text>().text = jsonResult;
}
}
Im not sure on the Code from MVC side if anyone could assist i would be very gratefull