StackAsk is a community where developers ask questions, share answers and learn from each others real-world experience, so every solved problem helps the next person who runs into it.
using System; using System.Collections; using UnityEngine; using UnityEngine.Networking; public class LoginHttps : MonoBehaviour { public void Login(string userName, string password, string url, Action onSuccess, Action onFailed) { // TODO: do somethings to validate user name & password from client //... StartCoroutine(IELogin(userName, password, url, onSuccess, onFailed)); } IEnumerator IELogin(string userName, string password, string url, Action onSuccess, Action onFailed) { WWWForm form = new WWWForm(); form.AddField("uid", userName); form.AddField("pass", password); using (UnityWebRequest www = UnityWebRequest.Post(url, form)) { yield return www.SendWebRequest(); if (www.isDone) { string response = www.downloadHandler.text; // response is a json string like: {code:0,err:"wrong password"} if (!string.IsNullOrEmpty(response)) { ResponseData result = JsonUtility.FromJson(response); if (result != null) { if (result.code == 1) { Debug.Log("Login Successfully."); onSuccess?.Invoke(); } else { Debug.LogError($"Login Failure: {result.err}"); onFailed?.Invoke(); } } } else { Debug.LogError("Something wrong from response, check your backend!"); onFailed?.Invoke(); } } else { Debug.LogError(www.error); // Network error or something wrong which can not post to url. onFailed?.Invoke(); } } } [System.Serializable] class ResponseData { public int code; // 0: Login Failed, 1: Login Success public string err; // Such as: Username is not exist, Wrong password... } }
2.2K Point(s)
1.2K Point(s)
313 Point(s)
178 Point(s)
138 Point(s)
Your account is signed in on the device(s) below. Sign out of at least one of them to continue signing in on this device.
Your account is signed in on the device(s) below. Sign out directly on one of those devices, or wait until the sign-in again time shown below.
If you cant access those devices, please contact the administrator to sign them out for you.
Input your email to receive reset password link, or if you remember your password, you can click