how to call Web API from ASP.Net application RRS feed

  • Question

  • User-1337882656 posted

    Want to call Web API from another asp.net application or console application. below is my code to call web api from my .net application.

    HttpResponseMessage resp = client.GetAsync("api/products").Result;
                    var products = resp.Content.ReadAsAsync<IEnumerable<APIMVC.Models.Product>>().Result;
                    foreach (var p in products)
                        Console.WriteLine("{0} {1} {2} ({3})", p.Id, p.Name, p.Price, p.Category);

    but it shows below error.

    An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.

    Help to find solution ASAP.

    Friday, April 17, 2015 5:44 AM