asp.net環境下web api接口接收參數方法

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)
{
}

 

這樣就可以接收大量數據了。

查看原文:

http://www.cnblogs.com/zhangtingzu/p/7060518.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章