【发布时间】:2015-04-23 11:02:05
【问题描述】:
我有一个如下所示的 WebAPI Get 方法
// GET api/Employee/5
public tblEmployee GettblEmployee(int id)
{
tblEmployee tblemployee = db.tblEmployees.Find(id);
if (tblemployee == null)
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
}
return tblemployee;
}
我正在尝试从 ASP.NET 互联网应用程序调用它
HttpClient hc;
hc = new HttpClient();
string uriStr = "http://localhost/api/Employee/";
HttpResponseMessage response = hc.GetAsync(uriStr + "2").Result;
var obj = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result);
ViewBag.Message = obj.ToString();
return View();
现在我想将 JSON 从 ASP 网站传递到 WebAPI,有人可以帮助我吗?我用谷歌搜索了很多,但我只能找到来自 JQuery 的调用
【问题讨论】:
标签: c# asp.net json asp.net-mvc asp.net-web-api