using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Net.Http; using System.Net.Http.Headers; using RestSharp; namespace jdis_import.RESTObjects { public class RESTService { //private string _baseUrl = "https://servicesbrandt.rpmindustries.com"; private string _baseUrl = "http://servicesbrandt.rpmindustries.com:8081"; private HttpClient _httpClient; public RESTService() { } public RESTService(string endPoint, Dictionary parameters) { _baseUrl = _baseUrl + "/" + endPoint; foreach (KeyValuePair kvp in parameters) { _baseUrl = _baseUrl + "/" + kvp.Key; if (!string.IsNullOrEmpty(kvp.Value)) _baseUrl = _baseUrl + "/" + kvp.Value; } _httpClient = new HttpClient(new HttpClientHandler { UseCookies = true, CookieContainer = new System.Net.CookieContainer() }) { BaseAddress = new Uri(_baseUrl), DefaultRequestHeaders = { Accept = { MediaTypeWithQualityHeaderValue.Parse("application/json") } } }; } public string RestGet(string endpoint, Dictionary parameters = null) { string url = _baseUrl + "/" + endpoint + '/'; RestClient client = new RestClient(url); RestRequest request = new RestRequest(endpoint, Method.Get); request.AddHeader("Accept", "application/json"); request.Method = Method.Get; RestResponse response = client.Execute(request); return response.Content; } public List RestGet(string endpoint) { RESTResponse> rest = new RESTResponse>(); string url = _baseUrl + "/" + endpoint + "/"; RestClient client = new RestClient(url); RestRequest request = new RestRequest(); request.Method = Method.Get; request.AddHeader("Accept", "application/json"); request.Method = Method.Get; RestResponse response = client.Execute(request); rest = Deserialize.FromJson>>(response.Content); List list = new List(); list.AddRange(rest.data); return list; } } }