- Home /
Application.LoadLevel Error (Possible cause: URL request conditioning went wrong)
Hi, I am currently working on a login function for my apps. When testing it with the correct Username and password, the server responds with status ok and it goes to the content page as intended. Then, testing it with the incorrect Username or password, as intended that the server responds with "authentication failure" but it still goes to the content page (unexpected) instead of going back to the login menu.
Can you help me point out what mistakes I've done that causes the error?
Here is my code (C#) :
IEnumerator Login() {
WWWForm form= new WWWForm ();
form.AddField ("name", usernamehere);
form.AddField ("pswd", passwordhere);
WWW download = new WWW (url, form);
yield return download;
if (download.error == null) {
Debug.Log (download.text);
goToContents();
}
else {
Debug.Log (download.text);
goBackToLoginMenu ();
}
}
void goBackToLoginMenu()
{
Application.LoadLevel ("LoginMenu");
}
void goToContents()
{
Application.LoadLevel ("Contents");
}
Answer by NeverHopeless · Aug 10, 2015 at 08:30 AM
As per the doc, you should not just check it for null
, you should check it for both null and empty string.
A part from doc:
If there was no error, error will return null or an empty string (this is because some platforms don't allow nulls for string values). We recommend that you use String.IsNullOrEmpty to check for the presence of an error so that both cases are covered.
Perhaps like this can resolve it:
if (string.IsNullOrEmpty(download.error)) {
Debug.Log (download.text);
goToContents();
}
else {
Debug.Log (download.text);
goBackToLoginMenu ();
}
Your answer
Follow this Question
Related Questions
Application.LoadLevel wont work 0 Answers
Collisions not working. 1 Answer
AdMob makes my game do strange things 0 Answers
Internal error when changing scene 0 Answers
Asset Bundle Download Problem 0 Answers