private T callReturn <T>(string path, string method, object body, int timeout, int retry, bool throwable, Encoding encoding, TransferCallback uploadProgress, TransferCallback downloadProgress, IDictionary <string, string> headers, CookieCollection cookies) { var t = 0; Exception error = null; while (t++ < retry) { try { var request = createRequest(path, method, timeout, headers, cookies); var stream = request.GetRequestStream(); if (body != null) { writeIntoStream(stream, body, encoding, uploadProgress); } var respose = request.GetResponse(); var contentLengh = respose.ContentLength; return(readStream <T>(contentLengh, respose.GetResponseStream(), encoding, downloadProgress)); } catch (Exception ex) { ErrorInterceptor?.Invoke(ex); error = ex; } } if (throwable && error != null) { throw error; } else { return(default(T)); } }
private async Task callNoReturnAsync(string path, string method, object body, int timeout, int retry, bool throwable, Encoding encoding, TransferCallback uploadProgress, IDictionary <string, string> headers, CookieCollection cookies) { var t = 0; Exception error = null; while (t++ < retry) { try { var request = createRequest(path, method, timeout, headers, cookies); var stream = await request.GetRequestStreamAsync().ConfigureAwait(false); if (body != null) { await writeIntoStreamAsync(stream, body, encoding, uploadProgress).ConfigureAwait(false); } await request.GetResponseAsync().ConfigureAwait(false); } catch (Exception ex) { ErrorInterceptor?.Invoke(ex); error = ex; } } if (throwable && error != null) { throw error; } }