我有一个web api方法: [HttpPost, ActionName("GET")] public string Get(string apiKey, DateTime start, DateTime end) { var user = db.Users.SingleOrDefault(u = u.Id == apiKey); if (user == null) { return string.Empty; } var records = db
[HttpPost, ActionName("GET")] public string Get(string apiKey, DateTime start, DateTime end) { var user = db.Users.SingleOrDefault(u => u.Id == apiKey); if (user == null) { return string.Empty; } var records = db.Histories.Where(h => h.Date >= start && h.Date <= end); return JsonConvert.SerializeObject(records); }
这是我试图调用该方法的URL,但它没有达到该方法.
http://localhost:11847/api/History/Get?apiKey=398cfa9b-8c5c-4cf4-b4f3-8904a827ff22&start=2014-01-01&end=2014-12-01
我也改变了WebApiConfig.cs
config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}", defaults: new { id = RouteParameter.Optional } );
从“api / {controller} / {id}到”api / {controller} / {action}
请帮忙.谢谢
要测试api,您可以使用fiddler( http://www.telerik.com/fiddler)或名为postman的chrome应用程序.您还应该在http://www.getpostman.com/之前尝试POSTMAN,它可以作为应用添加到chrome.这真的很好,让你组织你的api.