MVC4.0中WEBAPI通过HttpContextBase获取请求参数
WEBAPI中的Request是HttpRequestMessage类型,不能像Web传统那样有querystring和from 方法接收参数,而传统的HttpReqest的基类是HttpReqestBase
所以这里我们就直接使用(HttpContextBase)Request.Properties["MS_HttpContext"]
public void Post([FromBody]string value) { HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context HttpRequestBase request = context.Request;//定义传统request对象 string name = request.Form["name"]; }
文章来自:http://my.oschina.net/u/200350/blog/351245