webapi get/post 释疑

refs:

https://stackoverflow.com/questions/43703846/null-value-when-pass-values-frombody-to-post-method-by-postman-plugin

https://stackoverflow.com/questions/40853188/frombody-string-parameter-is-giving-null/40853424


1)

webaip 常用get/post等方法,

最好在方法上加注[HttpGet],[HttpPost]明确使用方法,

在ApiControl中方法名是隐晦的,只有通过方法参数来识别使用哪个方法来对应请求参数;


2)http post

post参数可以放在uri中也可以放在body中,

当放在uri中时通过[FromUri]可以获取,

当在body中时通过[FromBody]获取,

当以key-value格式放在body中,且Content-Type类型为'application/x-www-form-urlencoded' 时,服务器端需要以对象类型获取,否则获取不到;

见文首参考链接;


public object AskForRuntime([FromBody]MyModel mode)









猜你喜欢

转载自blog.csdn.net/henry_wu001/article/details/80351542
今日推荐