【问题标题】:Http post method in ASP .Net programatically以编程方式在 ASP .Net 中的 Http post 方法
【发布时间】:2013-08-15 08:51:01
【问题描述】:

我想在 mvc asp .net 网络服务中编写 http 帖子,该服务从 android 应用程序获取 BasicNameValuePair 返回一个 Json 数组。

你能帮帮人吗?

【问题讨论】:

    标签: android asp.net asp.net-mvc json.net


    【解决方案1】:
    [HttpPost]
    [WebMethod(EnableSession = true)]
    public string change()
    {
    
         int i=Request["id"] != null;
         System.Web.Script.Serialization.JavaScriptSerializer oSerializer =
         new System.Web.Script.Serialization.JavaScriptSerializer();
         string sJSON = oSerializer.Serialize(oList);
         return sJSON;
    }
    

    【讨论】:

      【解决方案2】:

      不完全确定您的要求,但听起来您想要一个接收键值对列表并返回 json 的端点。可以这样做:

      [HttpPost]
      public JsonResult MyMethod (IDictionary<string, object> inputParam) {
          var myArray = GetArrayFromSomewhere(inputParam); //possibly another webservice or database
          return Json(myArray, JsonRequestBehaviour.DenyGet);
      } 
      

      【讨论】:

      • 我可以在asp .net mvc web应用程序中插入一个web服务吗?
      • 您可以使用我上面建议的端点,像这样访问:/controller/mymethod 以及您的字典发布数据。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-13
      • 1970-01-01
      相关资源
      最近更新 更多