Skip to content
PiotrFerenc edited this page May 14, 2024 · 1 revision
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace Example
{
   public class Parameters
   {
       public string ConsoleText { get; set; }
   }

   public class TaskItem
   {
       public int Sequence { get; set; }
       public string Name { get; set; }
       public string Action { get; set; }
   }

   public class RequestPayload
   {
       public Parameters Parameters { get; set; }
       public TaskItem[] Tasks { get; set; }
   }

   class Program
   {
       static async Task Main(string[] args)
       {
           using (var client = new HttpClient())
           {
               var url = "http://localhost:5000/execute";

               var payload = new RequestPayload
               {
                   Parameters = new Parameters
                   {
                       ConsoleText = "hallo word"
                   },
                   Tasks = new[]
                   {
                       new TaskItem
                       {
                           Sequence = 1,
                           Name = "log",
                           Action = "console"
                       }
                   }
               };

               var jsonContent = JsonSerializer.Serialize(payload);
               var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");

               var response = await client.PostAsync(url, content);
               
               if (response.IsSuccessStatusCode)
               {
                   var responseContent = await response.Content.ReadAsStringAsync();
                   Console.WriteLine("Response: " + responseContent);
               }
               else
               {
                   Console.WriteLine("Error: " + response.StatusCode);
               }
           }
       }
   }
}
Clone this wiki locally