zoukankan      html  css  js  c++  java
  • asp.net mvc4 webapi request获取参数

    原文:http://blog.csdn.net/dyllove98/article/details/9075601/

    来园很长时间,不擅长交际的我,一直没有装饰家园,最近用mvc4中的WEBAPI,发现接收参数不是很方便,跟传统的request.querystring和request.form有很大区别,在网上搜了一大圈,各种方案都有,但不是太详细,于是跟踪Action中的变量,仔细查看,最后发现了解决方案,下面是代码:

    1  public void Post([FromBody]string value)
    2         {
    3             HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context
    4             HttpRequestBase request = context.Request;//定义传统request对象
    5             string name = request.Form["name"];
    6 
    7         }

    WEBAPI中的Request是HttpRequestMessage类型,不能像Web传统那样有querystring和from 方法接收参数,而传统的HttpReqest的基类是HttpReqestBase

    所以这里我们就直接使用(HttpContextBase)Request.Properties["MS_HttpContext"]


    <script type="text/javascript"><!-- google_ad_client = "ca-pub-1944176156128447"; /* cnblogs 首页横幅 */ google_ad_slot = "5419468456"; google_ad_width = 728; google_ad_height = 90; //--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

  • 相关阅读:
    oracle函数查询数据字典
    股票市场不是年轻人应该去的地方
    惊蟄
    大学问
    教条示龙场诸生
    生成器表达式
    三次锁定(文件加强版)
    文件的增删改查
    Python试题(1)
    Python入门(1)
  • 原文地址:https://www.cnblogs.com/lizhigang/p/7300336.html
Copyright © 2011-2022 走看看