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);
        }
    }
2

1 Answer 1

0

Change the value of unityWebRequest.useHttpContinue to false.

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.