static void Main(string[] args) { var consumer = new Consumer(); sangpart sang = new sangpart(123, 99, "13:18:55"); var spList = consumer.GetAllsp(); foreach (var sp in spList) { Console.WriteLine(sp); } Console.WriteLine($"forsøger at lave et sangpart obj: {sang}:"); Console.WriteLine(consumer.Post(sang)); Console.WriteLine("Printrt opdateret liste ud:"); foreach (sangpart spobj in consumer.GetAllsp()) { Console.WriteLine(spobj); } Console.ReadKey(); }
public bool Post(sangpart spobj) { // Laver body string json = JsonConvert.SerializeObject(spobj); StringContent content = new StringContent(json); // Her definerer vi at det er en Json vi sender og ikke eksempelvis XML content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); using (HttpClient client = new HttpClient()) { // sender HttpResponseMessage resultMessage = client.PostAsync("http://localhost:63145/api/Music", content).Result; if (resultMessage.IsSuccessStatusCode) { return(true); } return(false); } }
public void Post([FromBody] sangpart newSP) { spList.Add(newSP); }