Consuming a Web API with HttpClient using windows form
  • hi please how i can Consuming a Web API with HttpClient using windows form thank you so much :)
  • 1 Comment sorted by
  • You just need to pass web api url to HttpClient class like this:
    using (var client = new HttpClient())
    {
    client
    .BaseAddress = new Uri("http://localhost:9000/");
    client
    .DefaultRequestHeaders.Accept.Clear();
    client
    .DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

    // New code:
    HttpResponseMessage response = await client.GetAsync("api/products/1");
    if (response.IsSuccessStatusCode)
    {
    Product product = await response.Content.ReadAsAsync>Product>();
    Console.WriteLine("{0}\t${1}\t{2}", product.Name, product.Price, product.Category);
    }
    }
    http://www.asp.net/web-api/overview/advanced/calling-a-web-api-from-a-net-client



Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week

    Optimum Creative