-1

I am getting data from server using UnityWebRequest. At the first time it receives, when I update my data in server, the unity data is not updated and it shows me old data. I have to clear the cache and again get the data from server.

Here is the code.

public Text mytext;

void Start() 
{
    StartCoroutine(GetText());
}

IEnumerator GetText() 
{
    UnityWebRequest www = UnityWebRequest.Get("https://www.simplearcadegamers.com/wp-content/uploads/2019/GetData.php");
    yield return www.SendWebRequest();

    if(www.isNetworkError || www.isHttpError) 
    {
        Debug.Log(www.error);
    }
    else 
    {
        // Show results as text
        Debug.Log(www.downloadHandler.text);

        // Or retrieve results as binary data
        byte[] results = www.downloadHandler.data;
    }
}
derHugo
  • 83,094
  • 9
  • 75
  • 115
  • 3
    Where is the PHP in this question? – RiggsFolly May 29 '19 at 12:57
  • Possible duplicate of [WWW/UnityWebRequest POST/GET request won't return the latest data from server/url](https://stackoverflow.com/questions/38365749/www-unitywebrequest-post-get-request-wont-return-the-latest-data-from-server-ur) – derHugo May 29 '19 at 13:35

1 Answers1

1

Unity WWW caches results by default, as a quick workaround you can append a randomized query at the end of the URL to ensure it always returns new results, e.g. ?random=<generate random number here> - see: https://answers.unity.com/questions/209078/disable-cache-for-www.html

A proper way to do this would be to abandon using the now obsolete WWW classes, and do proper new requests via UnityWebRequest & disabling cache.

Tamás Deme
  • 2,194
  • 2
  • 13
  • 31