【发布时间】:2017-01-23 12:18:36
【问题描述】:
嘿嘿,
我无法通过查询字符串将数据发布到操作方法,该操作方法位于下面的控制器类中是我的代码。
我输入一个网址“http://localhost:53459/api/esb/post/test”来发布价值,但没有任何反应
任何帮助将不胜感激。
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{value}",
defaults: new { value = RouteParameter.Optional }
);
}
}
[RoutePrefix("api/esb")]
public class EsbController : ApiController
{
[Route("get")]
[HttpGet]
public string Get()
{
return "Hello there!";
}
[Route("post")]
[HttpPost]
[AcceptVerbs("POST")]
public string Post([FromUri]string value)
{
return string.Format("{0} is posted successfully ", value);
}
[Route("put")]
[HttpPut]
public string Put([FromUri] string value)
{
return string.Format("{0} is updated successfully ", value);
}
[Route("delete")]
[HttpDelete]
public string Delete(string value)
{
return string.Format("{0} is deleted successfully ", value);
}
}
【问题讨论】:
-
您不需要在 url 中使用 POST。所以应该是这样的:
http://localhost:53459/api/esb/test
标签: asp.net-web-api