Search Unity

[SOLVED]InputField.text not valid for UnityWebRequest

Discussion in 'Scripting' started by beanie4now, Mar 29, 2019.

  1. beanie4now

    beanie4now

    Joined:
    Apr 22, 2018
    Posts:
    311
    Using this code I can reliably get a successful response from the server

    Code (CSharp):
    1. IEnumerator TestAccess(string token)
    2.     {
    3.         print("Test");
    4.         WWWForm form = new WWWForm();
    5.         UnityWebRequest www = UnityWebRequest.Get("https://api.infusionsoft.com/crm/rest/v1/contacts?limit=1&access_token=exampletoken123"); // fix
    6.         yield return www.SendWebRequest();
    7.         if (www.isNetworkError || www.isHttpError)
    8.         {
    9.             Debug.Log(www.error);
    10.         }
    11.         else
    12.         {
    13.             Debug.Log("POST successful!");
    14.         }
    15.  
    16.     }
    However if I change the code to take the accesstoken from an input field it breaks

    Code (CSharp):
    1.  UnityWebRequest www = UnityWebRequest.Get("https://api.infusionsoft.com/crm/rest/v1/contacts?limit=1&access_token=" + token); // fix
    I also tried string.Conact

    How is
    Not the same as
    Because this works
     
    Last edited: Mar 29, 2019
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    Creepy and no. but that's what the Debug.Log is for. Just do this and check you are getting what you think you are.

    Code (CSharp):
    1.         var uri = "https://api.infusionsoft.com/crm/rest/v1/contacts?limit=1&access_token=" + token;
    2.  
    3.         Debug.Log(uri);
    4.  
    5.         UnityWebRequest www = UnityWebRequest.Get(uri);
     
  3. beanie4now

    beanie4now

    Joined:
    Apr 22, 2018
    Posts:
    311
    Tried that already, comes out looking perfect but still returns errors.
    Code (CSharp):
    1. print("RQ String:" + "https://api.infusionsoft.com/crm/rest/v1/contacts?limit=1&access_token=" + token);
     
  4. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    What do you get if you print the uri? And what is your error?
     
  5. beanie4now

    beanie4now

    Joined:
    Apr 22, 2018
    Posts:
    311
    the uri looks exactly as it should.
    as explained above any string creation using + or concat return error 401 access denied

    new development using this code
    Code (CSharp):
    1. PlayerPrefs.SetString("AccessToken", txtField.text);
    2.         txtField.text = "https://api.infusionsoft.com/crm/rest/v1/contacts?limit=1&access_token=" + PlayerPrefs.GetString("AccessToken");
    3.         print(txtField.text);
    4.         StartCoroutine(TestAccess(txtField.text));
    by setting whole string into the input text field i get a different server response
    PROGRESS
     
  6. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    Are you sure there is no unicode character somewhere inside your textfield? Maybe the ui text does not return a raw string? Just fyi, if you are working on mac, macos is hiding Unicode in Unity for no damn useful reason
     
  7. beanie4now

    beanie4now

    Joined:
    Apr 22, 2018
    Posts:
    311
    [SOLUTION]

    Code (CSharp):
    1. string s = "søme string";
    2. s = Regex.Replace(s, @"[^\u0000-\u007F]+", string.Empty);
     
    Last edited: Mar 30, 2019