diff --git a/ShareX.UploadersLib/BaseUploaders/Uploader.cs b/ShareX.UploadersLib/BaseUploaders/Uploader.cs index 7cd813f83..5bad6e9c6 100644 --- a/ShareX.UploadersLib/BaseUploaders/Uploader.cs +++ b/ShareX.UploadersLib/BaseUploaders/Uploader.cs @@ -139,7 +139,7 @@ protected string SendRequest(HttpMethod method, string url, Dictionary arguments = null, NameValueCollection headers = null, CookieCollection cookies = null, ResponseType responseType = ResponseType.Text) { - using (HttpWebResponse response = GetResponse(method, url, arguments, headers, cookies, content)) + using (HttpWebResponse response = GetResponse(method, url, content, null, arguments, headers, cookies)) + { + return ResponseToString(response, responseType); + } + } + + protected string SendRequestStream(string url, Stream stream, string contentType, NameValueCollection headers = null, + CookieCollection cookies = null, HttpMethod method = HttpMethod.POST, ResponseType responseType = ResponseType.Text) + { + using (HttpWebResponse response = GetResponse(method, url, stream, contentType, null, headers, cookies)) { return ResponseToString(response, responseType); } @@ -177,7 +186,7 @@ protected string SendRequest(HttpMethod method, string url, Stream content, Dict protected bool SendRequest(HttpMethod method, Stream downloadStream, string url, Dictionary arguments = null, NameValueCollection headers = null, CookieCollection cookies = null, string contentType = null) { - using (HttpWebResponse response = GetResponse(method, url, arguments, headers, cookies, null, contentType)) + using (HttpWebResponse response = GetResponse(method, url, null, contentType, arguments, headers, cookies)) { if (response != null) { @@ -189,48 +198,6 @@ protected bool SendRequest(HttpMethod method, Stream downloadStream, string url, return false; } - private HttpWebResponse GetResponse(HttpMethod method, string url, Dictionary arguments = null, NameValueCollection headers = null, - CookieCollection cookies = null, Stream dataStream = null, string contentType = null) - { - IsUploading = true; - StopUploadRequested = false; - - url = CreateQuery(url, arguments); - - try - { - HttpWebRequest request = PrepareWebRequest(method, url, headers, cookies, contentType); - - if (dataStream != null) - { - using (Stream requestStream = request.GetRequestStream()) - { - if (!TransferData(dataStream, requestStream)) - { - return null; - } - } - } - - return (HttpWebResponse)request.GetResponse(); - } - catch (Exception e) - { - if (!StopUploadRequested) - { - if (WebExceptionThrow && e is WebException) throw; - AddWebError(e); - } - } - finally - { - currentRequest = null; - IsUploading = false; - } - - return null; - } - protected string SendRequestJSON(string url, string json, NameValueCollection headers = null, CookieCollection cookies = null, HttpMethod method = HttpMethod.POST) { MemoryStream stream = null; @@ -265,19 +232,10 @@ protected string SendRequestURLEncoded(string url, Dictionary ar } } - protected string SendRequestStream(string url, Stream stream, string contentType, NameValueCollection headers = null, - CookieCollection cookies = null, HttpMethod method = HttpMethod.POST, ResponseType responseType = ResponseType.Text) - { - using (HttpWebResponse response = GetResponse(url, stream, contentType, headers, cookies, method)) - { - return ResponseToString(response, responseType); - } - } - protected NameValueCollection SendRequestStreamGetHeaders(string url, Stream stream, string contentType, NameValueCollection headers = null, CookieCollection cookies = null, HttpMethod method = HttpMethod.POST) { - using (HttpWebResponse response = GetResponse(url, stream, contentType, headers, cookies, method)) + using (HttpWebResponse response = GetResponse(method, url, stream, contentType, null, headers, cookies)) { if (response != null) { @@ -298,23 +256,25 @@ private HttpWebResponse SendRequestMultiPart(string url, Dictionary args = null, + NameValueCollection headers = null, CookieCollection cookies = null) { IsUploading = true; StopUploadRequested = false; try { + url = CreateQuery(url, args); + long length = 0; - if (dataStream != null) + if (data != null) { - length = dataStream.Length; + length = data.Length; } HttpWebRequest request = PrepareWebRequest(method, url, headers, cookies, contentType, length); @@ -323,7 +283,10 @@ private HttpWebResponse GetResponse(string url, Stream dataStream, string conten { using (Stream requestStream = request.GetRequestStream()) { - if (!TransferData(dataStream, requestStream)) return null; + if (!TransferData(data, requestStream)) + { + return null; + } } }