Search Unity

WWW Get Request with credentials not working anymore in Unity 2017.1.0f3

Discussion in 'Scripting' started by mowax74, Jul 27, 2017.

  1. mowax74

    mowax74

    Joined:
    Mar 3, 2015
    Posts:
    97
    So, what we have since Unity 4 is following code:

    Code (CSharp):
    1.  
    2. string url = "https://www.domain.com/test.php?var1=value1&var2=value2";
    3. string credentials = "user:pass";
    4.  
    5. Dictionary<string, string> headers = new Dictionary<string, string>() { { "Authorization", "Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(credentials)) } };
    6.  
    7. WWW www = new WWW(url, null, headers);
    8. yield return www;
    9.  
    10. if (www.error != null) {
    11.     // error handling
    12.     Debug.LogWarning (string.Format ("Error: {0}", www.error));
    13.     yield break;
    14. }
    15.  
    16. // work with www result
    17.  
    It's a bit simplified, the url is %-escaped.

    This worked fine from unity 4 to 5.6.2, but is not working anymore in unity 2017.1.0f3.
    Now it throws an error without an error message.

    What has changed there?

    Thanks!
     
  2. mowax74

    mowax74

    Joined:
    Mar 3, 2015
    Posts:
    97
    Ok, i got it. Stupid mistake. They changed that the error-message is not null anymore, now it is an empty string. So there was not really an error, but it did the error handling and jumped out of the ienumerator. Testing with !string.IsNullOrEmpty() solved it.