public static async void PostSimple(string url, string binaryString, JSONReturnCallBack callBack) { string responseString = String.Empty; try { using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(getConnectionDetails()))); using (System.Net.Http.HttpResponseMessage response = client.PostAsync(SetURL(url), new StringContent(binaryString,Encoding.UTF8,"application/json")).Result) { response.EnsureSuccessStatusCode(); responseString = await response.Content.ReadAsStringAsync(); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadLine(); } callBack(responseString, "file"); }
public static async void Patch(string url, System.Net.Http.HttpContent wiPostDataContent, JSONReturnCallBack callBack) { string responseString = String.Empty; try { using (HttpClient client = new System.Net.Http.HttpClient()) { client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json-patch+json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(getConnectionDetails()))); using (System.Net.Http.HttpResponseMessage response = client.PatchAsync(SetURL(url), wiPostDataContent).Result) { response.EnsureSuccessStatusCode(); string ResponseContent = await response.Content.ReadAsStringAsync(); responseString = ResponseContent; } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadLine(); } callBack(responseString, String.Empty); }