从web api获取价值 [英] get value from web api

查看:63
本文介绍了从web api获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的控制器名称是testController而我的api是

my controller name is "testController" and my api as

[HttpGet]
     [ActionName("test_api")]
     public string test_api(ret request)
     {
         return "nesreen";
     }





我想从另一个项目打电话给这个api



所以我用这个



and I want to call this api from another project

so I use this

 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

            }
}







但是我仍然无法打电话给我的控制器和我的网页api的名字





请帮助我




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


please help me

推荐答案

你可以帮助我这个artcle。我想你将能够解决你的问题。



http://www.asp.net/web-api/overview/advanced/calling-a-web-api-from-a-net-client [ ^ ]
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[^]


这篇关于从web api获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆