i am send data using unitywebrequest but db/server is getting empty json string.
public class Credentials : Singleton<Credentials>
{
public string email;
public string password;
public string ConvertToJason()
{
return JsonUtility.ToJson(this);
}
}
public class LogIn : MonoBehaviour
{
public InputField emailAddress;
public InputField passwordField;
public GameObject loadingCanvas;
public GameObject loginButton;
public GameObject loadingImg;
string Url = "http://www.abc.com/test_api/user_auth.php";
public void LoginButton()
{
loginButton.SetActive(false);
loadingImg.SetActive(true);
if (emailAddress.text == "" || passwordField.text == "")
{
Debug.Log("Empty");
loginButton.SetActive(true);
loadingImg.SetActive(false);
}
else
{
Credentials.Instance.email = emailAddress.text.ToString();
Credentials.Instance.password = passwordField.text.ToString();
//StartCoroutine(LogInAuthenticate());
Value = Credentials.Instance.ConvertToJason();
Debug.Log(Value);
StartCoroutine(LogInAuthenticate());
}
loginButton.SetActive(true);
loadingImg.SetActive(false);
}
string Value;
IEnumerator LogInAuthenticate()
{
using (UnityWebRequest www = UnityWebRequest.Post(Url, Value))
{
www.SetRequestHeader("Content-Type", "application/json");
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
Debug.LogError ("Web Issue : "+ www.error);
}
else
{
string responseText = www.downloadHandler.text;
Debug.Log("Log Message : " + responseText);
if (responseText.StartsWith("Authenticate Successfully"))
{
Debug.Log("Sucess :" + responseText);
}
else
{
Debug.LogError("Log Issue : " + responseText);
}
}
}
}
}
php code is working fine on postman application.
all data is being handled in json