【发布时间】:2012-04-07 23:49:22
【问题描述】:
使用新的 web api,是否可以像使用 catch all 路由一样
routes.MapHttpRoute(
name: "name",
routeTemplate: "api/{*id}",
defaults: new { controller = "mycontroller", id = RouteParameter.Optional}
);
使用 PUT 方法?通常使用 PUT 方法,如
public HttpResponseMessage Put(string id, string body)
{
...
}
body 是 PUT 请求的正文。但是,通过一条全能路线,这似乎不起作用,我收到了错误
{
"ExceptionType":"System.ArgumentException",
"Message":":"No 'MediaTypeFormatter' is available to read an object of type 'String' with the media type ''undefined''.",
"StackTrace":"..."
}
我的 put 方法的样子
public HttpResponseMessage Put(string id)
{
...
}
我认为我应该能够使用 catch all 路由,其中路由信息将传递给 id 参数,并且我应该能够从响应对象访问正文。有什么想法吗?
【问题讨论】:
标签: c# asp.net asp.net-web-api put