using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace APICLI { internal class Program { static void Main(string[] args) { try { using (var client = new HttpClient()) { // 🔐 Bearer Token string json = System.IO.File.ReadAllText(args[1].ToString()); string ApiUrl = Properties.Settings.Default.resturi + args[0].ToString(); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Properties.Settings.Default.token); var content = new StringContent( json, Encoding.UTF8, "application/json"); var response = client.PostAsync(ApiUrl, content).Result; var responseText = response.Content.ReadAsStringAsync().Result; if (!response.IsSuccessStatusCode) { // optional: Logging Console.WriteLine($"Error: {response.StatusCode} - {responseText}"); } var jsonResult = JObject.Parse(responseText); Console.WriteLine(responseText); } } catch (Exception ex) { // Logging Console.WriteLine(ex.Message); } } } }