using System; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; namespace RIZO.Client.DAL { public class WebDataAccess { protected string domain = "http://localhost:5000/api/"; public Task GetDatas(string url) { using (HttpClient client = new HttpClient()) { var resp = client.GetAsync(url).GetAwaiter().GetResult(); return resp.Content.ReadAsStringAsync(); } } private MultipartFormDataContent GetFormData(Dictionary contents) { var postContent = new MultipartFormDataContent(); string boundary = $"-------{DateTime.Now.Ticks.ToString("x")}-----------"; postContent.Headers.Add("ContentType", $"muiltipart/form-data,boundary={boundary}"); foreach (var item in contents) { postContent.Add(item.Value, item.Key); } return postContent; } public Task PostDatas(string url, Dictionary contents) { using (HttpClient client = new HttpClient()) { var resp = client.PostAsync(url, this.GetFormData(contents)).GetAwaiter().GetResult(); return resp.Content.ReadAsStringAsync(); } } public Task PostDatas(string url, HttpContent contents) { using (HttpClient client = new HttpClient()) { var resp = client.PostAsync(url, contents).GetAwaiter().GetResult(); return resp.Content.ReadAsStringAsync(); } } } }