1

I use Unity Web Request in my project to send POST and GET requests to the server. It works correctly most of the time, but sometimes the response of the request is not right and when I check logs, I find out that the response of that request, is exactly response of the one before the latest response and because of that my project crash.

    IEnumerator IUnityWebRequest(HTTPRequest request, Action<string> successCallback, Action<string> failCallback, bool hasLoading = true)
    {
        UnityWebRequest www = null;
        if (request.requestType == HTTPRequestType.GET)
        {
            var parameters = FormatedParameters(request.parameters);
            www = UnityWebRequest.Get(request.url + parameters);
        }
        else
        {
            www = new UnityWebRequest(request.url, UnityWebRequest.kHttpVerbPOST);

            byte[] bytes = Encoding.UTF8.GetBytes(request.body);
            www.uploadHandler = (UploadHandler)new UploadHandlerRaw(bytes);
            www.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();


        }

        foreach (KeyValuePair<string, string> entry in request.headers)
            www.SetRequestHeader(entry.Key, entry.Value);
        www.timeout = timeOut;

        yield return www.SendWebRequest();

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log(www.error);
            if(www.error == "Request timeout")
            {
                failCallback("timeout");
            }
            else
            {
                failCallback(www.downloadHandler.text);
            }
        }
        else
        {
            Debug.LogFormat("Response url: {0} | Message {1} ", www.url, www.downloadHandler.text);

            successCallback(www.downloadHandler.text);
        }
    }
  • 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 Jun 17 '19 at 07:32
  • You can give a try https://github.com/shamsdev/davinci – Phd. Burak Öztürk Nov 22 '20 at 15:18

1 Answers1

0

Change the value of unityWebRequest.useHttpContinue to false.

Reference: https://forum.unity.com/threads/unitywebrequest-keeps-caching.519489/#post-4136944

Ali.Rahmanian
  • 57
  • 1
  • 2