asp.net環境下web api接口接收參數方法
public static string GetRequestString(string name, string defaultValue) { string result = defaultValue; if (HttpContext.Current != null && HttpContext.Current.Request != null) { if (HttpContext.Current.Request.QueryString[name] != null || HttpContext.Current.Request.Form[name] != null) { result = HttpContext.Current.Request[name].ToString(); } } return result; } string value = RequestUtil.GetRequestString("param", "");
缺點:當參數數據量比較大時,數據會被截斷,需要用下面的方法。
[HttpPost] public bool Write([FromBody] List<StudentEntity> model) { } [HttpPost] public bool Write<T>([FromBody]T model) { }
這樣就可以接收大量數據了。
查看原文: