public string RetrieveJson(string url, int?limit = null, int?offset = null) { string json = null; if (limit == 0) { limit = null; } if (string.IsNullOrEmpty(url)) { return(null); } try { if (!url.Contains("client_id=")) { url += (url.Contains("?") ? "&" : "?") + "client_id=" + _clientID; } if (limit != null) { url += "&limit=" + limit; } if (offset != null) { url += "&offset=" + offset; } if (limit != null) { url += "&linked_partitioning=1"; //will add next_href to the response } var result = DownloadUtils.httpClient.SendAsync(DownloadUtils.RequestMessageWithHeaders($"{url}", HttpMethod.Get)).Result; json = result.Content.ReadAsStringAsync().GetAwaiter().GetResult(); if (!result.IsSuccessStatusCode) { throw new Exception(json); } } catch (Exception e) { _manifestUtil.ProgressUtil.HasErrors = true; ExceptionHandlerUtils.HandleException(e); } return(json); }
public string RetrieveJson(string url, int?limit = null, int?offset = null) { string json = null; if (limit == 0) { limit = null; } if (string.IsNullOrEmpty(url)) { return(null); } try { using (var client = new WebClient()) { client.Encoding = Encoding.UTF8; if (!url.Contains("client_id=")) { url += (url.Contains("?") ? "&" : "?") + "client_id=" + _clientID; } if (limit != null) { url += "&limit=" + limit; } if (offset != null) { url += "&offset=" + offset; } if (limit != null) { url += "&linked_partitioning=1"; //will add next_href to the response } json = client.DownloadString(url); } } catch (Exception e) { _manifestUtil.ProgressUtil.IsError = true; ExceptionHandlerUtils.HandleException(e); } return(json); }