Hi all, I get an error in the console from time to time: curl error 56: Receiving data failed with unitytls error code 1048578 I use UnityWebRequest to call a back-end. Most of the time it works but sometimes it gives me this error. My script will retry the call and it will get a restult back. But is there a way to better capture this? I do not like theses errors in console. And when the error happens. It takes a long time to make the call before it retries. this is how I make calls. api.url is the endpoint url data is a string (containing json object but stringified.) To post data instead of PUT but using a string (data) instead of a form I use the PUT webrequest but change the method to POST. Code (CSharp): protected IEnumerator ApiCall(string data, Action<string> successCallback = null, Action failCallback = null) { bool IsHttpError; bool IsNetworkError; int retries = 0; do { MonoBehaviour.print(data); using UnityWebRequest www = UnityWebRequest.Put(api.url, data); www.method = "POST"; #if UNITY_2017_2_OR_NEWER yield return www.SendWebRequest(); #else yield return request.Send(); #endif #if UNITY_2020_2_OR_NEWER IsHttpError = www.result == UnityWebRequest.Result.ProtocolError; #else IsHttpError = www.isHttpError; #endif #if UNITY_2020_2_OR_NEWER IsNetworkError = www.result == UnityWebRequest.Result.ConnectionError; #else IsNetworkError = request.isNetworkError; #endif if (IsHttpError || IsNetworkError || !www.isDone) { if (retries < 3) { yield return new WaitForSeconds(1f); retries++; } else { MonoBehaviour.print("Error..."); MonoBehaviour.print(www.error.ToString()); failCallback?.Invoke(); break; } } else { MonoBehaviour.print(www.downloadHandler.text.ToString()); successCallback?.Invoke(www.downloadHandler.text); break; } } while (retries <= 3); }
I changed the code to use POST from the start instead of the method = POST trick. But no luck. Same issue. Here is the modified code: Code (CSharp): protected IEnumerator ApiCall(string data, Action<string> successCallback = null, Action failCallback = null) { bool IsHttpError; bool IsNetworkError; int retries = 0; do { MonoBehaviour.print(data); UnityWebRequest www = new UnityWebRequest(api.url, "POST"); byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes(data); www.uploadHandler = new UploadHandlerRaw(jsonToSend); www.downloadHandler = new DownloadHandlerBuffer(); www.SetRequestHeader("Content-Type", "application/json"); #if UNITY_2017_2_OR_NEWER yield return www.SendWebRequest(); #if UNITY_2020_2_OR_NEWER IsHttpError = www.result == UnityWebRequest.Result.ProtocolError; IsNetworkError = www.result == UnityWebRequest.Result.ConnectionError; #else IsHttpError = www.isHttpError; IsNetworkError = request.isNetworkError; #endif #else yield return request.Send(); IsHttpError = www.isError; IsNetworkError = www.isError; #endif if (IsHttpError || IsNetworkError || !www.isDone) { if (retries < 3) { yield return new WaitForSeconds(1f); retries++; } else { MonoBehaviour.print("Error..."); MonoBehaviour.print(www.error.ToString()); failCallback?.Invoke(); break; } } else { MonoBehaviour.print(www.downloadHandler.text.ToString()); successCallback?.Invoke(www.downloadHandler.text); break; } } while (retries <= 3); }
Oh, I have opted out in privacy settings (id.unity) and also disabled editor analytics (I'm using pro).
Is the server something we can access? It would be nice to get a bug report for this so we could look, though that will require for us to be able to perform the same requests.