using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Runtime.CompilerServices; using System.Text; using System.Text.Json; using System.Threading.Tasks; namespace EPAServeur.BDAccess { public class APIAccess { private static APIAccess instance = null; private string serveur = "http://www.epa.apside.com/api"; private APIAccess() { } public static APIAccess getInstance() { return instance; } public static List requestGetAPI(string query) { if (instance == null) { instance = new APIAccess(); } List result = new List(); WebClient client = new WebClient(); result = JsonSerializer.Deserialize>(client.DownloadString(instance.serveur+query)); return result; } public static List requestPostAPI(string query, List> postParam = null) { if (instance == null) { instance = new APIAccess(); } List result = new List(); WebClient client = new WebClient(); client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; if (postParam != null) { foreach (KeyValuePair arg in postParam) { client.QueryString.Add(arg.Key, arg.Value); } } try { var data = client.UploadValues(query, "POST", client.QueryString); result = JsonSerializer.Deserialize>(UnicodeEncoding.UTF8.GetString(data)); } catch { result = null; } return result; } } }