public IEnumerator Send() { // Employing `using` will ensure that the UnityWebRequest is properly cleaned in case of uncaught exceptions using (www = new UnityWebRequest(Url(), Method())) { www.timeout = timeout; if (body != null) { UploadHandler uploader = new UploadHandlerRaw(body.Body()); uploader.contentType = body.ContentType(); www.uploadHandler = uploader; } if (headers != null) { foreach (KeyValuePair <string, string> header in headers) { www.SetRequestHeader(header.Key, header.Value); } } www.downloadHandler = new DownloadHandlerBuffer(); yield return(www.Send()); if (www.isNetworkError) { response = new SimpleHTTP.Response(www.error); } else { response = new SimpleHTTP.Response(www.responseCode, www.downloadHandler.text, www.downloadHandler.data); } } }
public IEnumerator Send(Request request) { // Employing `using` will ensure that the UnityWebRequest is properly cleaned in case of uncaught exceptions using (www = new UnityWebRequest(request.Url(), request.Method())) { www.timeout = request.Timeout(); RequestBody body = request.Body(); if (body != null) { UploadHandler uploader = new UploadHandlerRaw(body.Body()); uploader.contentType = body.ContentType(); www.uploadHandler = uploader; } Dictionary <string, string> headers = request.Headers(); if (headers != null) { foreach (KeyValuePair <string, string> header in headers) { www.SetRequestHeader(header.Key, header.Value); } } www.downloadHandler = new DownloadHandlerBuffer(); yield return(www.Send()); if (www.isNetworkError) { error = www.error; } else { response = SimpleHTTP.Response.From(www); } } }