public async Task <DownloadDataResponse> DownloadData(DownloadDataRequest request) { try { var httpClient = GetHttpClient(); var content = new StringContent(JsonConvert.SerializeObject(request), System.Text.Encoding.UTF8, "application/json"); var result = await httpClient.PostAsync(DownloadServerUri, content); if (!result.IsSuccessStatusCode) { return(new DownloadDataResponse()); } var resultString = await result.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <DownloadDataResponse>(resultString)); } catch (WebException) { return(new DownloadDataResponse()); } catch (Exception e2) { Debug.WriteLine($"{e2}"); return(new DownloadDataResponse()); } }
public DownloadDataResponse DownloadWith(DownloadDataRequest request) { DownloadDataResponse response = new(); try { using (WebClient webClient = new()) { response.Data = webClient.DownloadData(request.Uri); } } catch (Exception e) { response.Message = $"An error occurred while attempting to download file from {request.Uri}:{Environment.NewLine}{e.Message}"; } return(response); }