Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my controller name is "testController" and my api as
C#
[HttpGet]
     [ActionName("test_api")]
     public string test_api(ret request)
     {
         return "nesreen";
     }


and I want to call this api from another project

so I use this
C#
 public static string callapi()
        {


            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri("http://localhost:52559/");
            //client.DefaultRequestHeaders.Add("appkey", "myapp_key");
            client.DefaultRequestHeaders.Accept.Add(
               new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = client.GetAsync("api/test").Result;
            if (response.IsSuccessStatusCode)
            {
   // i want here to extract the string that returned from my api

            }
}



but I still cant call my controller and name of my web api


please help me
Posted

1 solution

You can take help of this artcle. I think you will be able to solve your problem.

http://www.asp.net/web-api/overview/advanced/calling-a-web-api-from-a-net-client[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900