public static IEnumerator DefaultUnityWebRequest(RequestHelper options, object bodyJson, string method, Action <Exception, ResponseHelper> callback) { using (var request = new UnityWebRequest(options.url, method)) { yield return(request.SendWebRequest(options, bodyJson)); var response = request.CreateWebResponse(); if (request.isDone && string.IsNullOrEmpty(request.error)) { callback(null, response); } else { callback(new RequestException(request.error, request.isHttpError, request.isNetworkError), response); } } }
public static IEnumerator DefaultUnityWebRequest <TResponse>(RequestHelper options, object bodyJson, string method, Action <Exception, ResponseHelper, TResponse> callback) { using (var request = new UnityWebRequest(options.url, method)) { yield return(request.SendWebRequest(options, bodyJson)); var response = request.CreateWebResponse(); if (request.isDone && string.IsNullOrEmpty(request.error)) { var body = JsonUtility.FromJson <TResponse>(request.downloadHandler.text); callback(null, response, body); } else { callback(new RequestException(request.error, request.isHttpError, request.isNetworkError), response, default(TResponse)); } } }
public static IEnumerator DefaultUnityWebRequest <TResponse>(RequestHelper options, Action <Exception, ResponseHelper, TResponse> callback) { using (var request = new UnityWebRequest(options.Uri, options.Method)) { yield return(request.SendWebRequest(options, options.Body)); var response = request.CreateWebResponse(); if (request.IsValidRequest(options)) { callback(null, response, JsonUtility.FromJson <TResponse>(request.downloadHandler.text)); } else { var message = request.error ?? request.downloadHandler.text; callback(new RequestException(message, request.isHttpError, request.isNetworkError, request.responseCode), response, default(TResponse)); } } }