Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

réponse www.text non comprise par mon script

Discussion in 'Scripting' started by Papirax, Nov 17, 2017.

  1. Papirax

    Papirax

    Joined:
    Nov 25, 2014
    Posts:
    19
    hello, I have an incomprehensible concern.
    I send a request to my server (localhost).
    2 it does not send me error code but, in my PHP script a confirmation by (echo = "1") if my datas are correct (login, pass).
    3 in my C # script my debug.log line responds well "* 1 *" but my if (www.text == "1") does not detect it
    there I am dropped I do not understand why the www.text is not recognized as "1"

    I thank you in advance for your answers.


    bonjours, j'ai un souci incompréhensible.
    1 j'envois une requête à mon serveur (localhost).
    2 il ne me renvoie pas de code erreur mais, dans mon script PHP une confirmation par (echo = "1") si mes datas sont corrects (login,pass).
    3 dans mon script C# ma ligne debug.log répond bien "*1*" mais mon if (www.text == "1") ne le détecte pas
    là je suis largué je ne comprends pas pourquoi le www.text n’est pas reconnu comme "1"

    je vous remercie par avance pour vos réponses.
    .........
    yield return www;
    if (www.error == null)
    {
    Debug.Log ("*" + www.text + "*"); = *1*
    if (www.text == "1")
    {
    Debug.Log ("passer 3er etape");
    Logmsg.color = Color.green;
    Logmsg.text = "Login in the courtyard please wait";
    StartCoroutine (Menu ());
    }
    else
    {
    Logmsg.color = Color.red;
    Logmsg.text = "Invalid login or password";
    }
    }
    else
    {
    Debug.Log (www.error);
    if (www.error == "Could not resolve host")
    {
    Logmsg.color = Color.red;
    Logmsg.text = "Unavailable server";
    }
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    Try checking www.text.Length or printing the codes for individual characters.
     
  3. Papirax

    Papirax

    Joined:
    Nov 25, 2014
    Posts:
    19
  4. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,083
    It sounds like it's your php output that's incorrect - it's most likely outputting some UTF-8 BOM header or Unicode characters that Unity doesn't like.

    Make sure your php file is encoded as UTF-8 (e.g. open in notepad2, go to file->encoding->utf-8). This is important as the PHP file type determines how the server outputs any text from it. (unless you've specifically set the output as part of the HTTP header)
     
  5. Papirax

    Papirax

    Joined:
    Nov 25, 2014
    Posts:
    19
    thank you, I will control but for the moment I have avoided the problem with this line

    string re = (www.text [1]).ToString ();