我有這樣的控制器操作:WebApi POST無[FromBody]工作?
[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]屬性?我還需要/不寫這個屬性?
另外,什麼是不寫這個屬性的場景 - 會導致問題?
有趣的問題。我在這裏找到了一些信息:http://encosia.com/using-jquery-to-post-frombody-parameters-to-web-api/ – 2014-11-22 09:59:32