【发布时间】:2014-11-22 09:53:03
【问题描述】:
我有这个控制器动作:
[HttpPost]
[ActionName("aaa")]
public HttpResponseMessage aaa(Z z) //notice - no [FromBody]
{
return Request.CreateResponse(HttpStatusCode.OK, 1);
}
Z 在哪里:
public class Z
{
public string a { get; set; }
}
但是当我通过提琴手发帖时:
POST http://localhost:11485/api/profiles/aaa HTTP/1.1
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Host: localhost:11485
Content-Length: 3
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,he;q=0.6
Cache-Control: no-cache
Connection: keep-alive
a=1
我实际上可以看到它正在工作:
问题:
如果是这样,如果没有 [FromBody] 属性,它如何工作?我还需要/不写这个属性吗?
另外,什么情况下不写这个属性会导致问题?
【问题讨论】:
-
有趣的问题。我在这里找到了一些信息:encosia.com/using-jquery-to-post-frombody-parameters-to-web-api
标签: c# post asp.net-web-api