Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to implement the new method UnityWebRequest here?

Discussion in 'Scripting' started by dlolg, Oct 21, 2019.

  1. dlolg

    dlolg

    Joined:
    Sep 25, 2018
    Posts:
    13
    How to implement the new method UnityWebRequest here?
    I tried it but on the line ... .. Debug.Log((System.Text.Encoding.UTF8.GetString(DataPost.bytes))); ..... it makes me wrong





    Code (CSharp):
    1. IEnumerator EnviarNick(string nombreJugador)
    2.     {
    3.         string hash = Md5Sum(nombreJugador + claveSecreta);
    4.         string PostURL = URLVerNick + "players=" + WWW.EscapeURL(nombreJugador) + "&hash=" + hash;
    5.  
    6.         WWW DataPost = new WWW("https://" + PostURL);
    7.         yield return DataPost;
    8.  
    9.         if (DataPost.error != null)
    10.         {
    11.             print("Problema al intentat enviar jugador a la base de datos:-"+ DataPost.error);
    12.         }
    13.         else
    14.        
    15.             //print("Datos enviados:-" + DataPost.error);
    16.             Debug.Log((System.Text.Encoding.UTF8.GetString(DataPost.bytes)));
    17.  
    18.     }
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,745
    You're using obsolete API new WWW, you'd better switch to UnityWebRequest. Also, what's wrong with that line? It looks correct to me.
     
  3. dlolg

    dlolg

    Joined:
    Sep 25, 2018
    Posts:
    13
    if I try to use with new UnityWebRequest

    I have error in bytes
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,653
    Show the code with UnityWebRequest.
    And the way you construct the URL look fishy to me, try printing out the URL before sending request and check if it is correct.
     
  5. dlolg

    dlolg

    Joined:
    Sep 25, 2018
    Posts:
    13
    I've tried it that way...

    Code (CSharp):
    1. IEnumerator EnviarNickUnityWebRequest(string nombreJugador)
    2.     {
    3.         string hash = Md5Sum(nombreJugador + claveSecreta);
    4.         string PostURL = URLVerNick + "players=" + UnityWebRequest.EscapeURL(nombreJugador) + "&hash=" + hash;
    5.  
    6.         UnityWebRequest DataPost = new UnityWebRequest("https://" + PostURL);
    7.         yield return DataPost;
    8.  
    9.         if (DataPost.error != null)
    10.         {
    11.             print("Problema al intentat enviar jugador a la base de datos:-" + DataPost.error);
    12.         }
    13.         else
    14.  
    15.             //print("Datos enviados:-" + DataPost.error);
    16.             Debug.Log((System.Text.Encoding.UTF8.GetString(DataPost.bytes))); // i have the problem here in bytes
    17.  
    18.     }
     
  6. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,653
    This is your bug. Should be:
    yield return DataPost.SendWebRequest();