C# HttpClient to post information without waiting for response

Viewed 10122

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);
}
2 Answers
Related