I am using HttpClient class in my asp.net web api 2 application to post some information to a endpoint. I just want to post the information without waiting for a response. Is this the right syntax
using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:9000/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // HTTP POST var gizmo = new Product() { Name = "Gizmo", Price = 100, Category = "Widget" }; var response = await client.PostAsJsonAsync("api/products", gizmo); }
HttpClientfrom an ASP.NET WebApi app?awaitkeyword, I get following messagebecause this call is not awaited execution of the current method continues before the call is completed