通过HTTP GET发送JSON对象到服务器 [英] Sending JSON object to the server via http GET

查看:838
本文介绍了通过HTTP GET发送JSON对象到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找通过GET发送JSON对象到服务器。
克里斯对<一个答案href=\"http://stackoverflow.com/questions/4789481/post-an-array-of-objects-via-json-to-asp-net-mvc3\">Post通过JSON对象数组来ASP.Net MVC3的HTTP POST而不是GET 工作。
我的情况也适用于POST而不是GET。我能做些什么,以找到工作
这里是我的情况:
在控制器我有以下方法
       公众的ActionResult Screenreport(Screentable screendata)

I am looking for sending JSON object to the server via GET. Chris's answer on Post an Array of Objects via JSON to ASP.Net MVC3 works for the http POST but not for GET. My case also works for POST but not for GET. What can I do to make GET work Here is my case: in Controller I have the following method public ActionResult Screenreport(Screentable screendata)

   {
       // do something here
       return View();
   }

我有两个模型视图如下:

I have two ModelView as follows:

   public class Screenrecord
   {
      public string Firstname{ get; set; }
      public string Lastname{ get; set; }
   }
   public class Screentable
   {
      public List<Screenrecord> Screenlist { get; set; } 
   }

在客户端生成我JSON对象

On the client side I generate JSON object

var Screentable = { Screenlist: screendata };

screendata是Screenrecord的阵列

screendata is an array of Screenrecord

当我使用POST,但所有这些工作时,我使用GET我得到空值(screendata = NULL)控制器的方法。
换句话说,当点击GO,screendata是空的Screenreport(Screentable screendata)例程。

All this work when I use POST but when I use GET I am getting null value (screendata = null) Controllers' method. In other word when click GO, screendata is null in Screenreport(Screentable screendata) routine.

另外,如果我发送一个JSON对象,它的工作原理,但如果我喜欢送我描述一个数组(清单),它没有。
就是我试图做是可行的?

Also, if I send one JSON object it works but if I send an array (list) like I described, it does not. Is what I am trying to do doable?

推荐答案

没有:-)
那不是怎么弄的作品。

No :-) Thats not how get works.

http://www.w3.org/Protocols/rfc2616/rfc2616- sec9.html

(见9.3 GET)

GET方法意味着获取的任何信息(以实体的形式)是由Request-URI标识

"The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI"

请求URI是这里的重要组成部分。有一个在没有身体数据概念的获取请求。

Request-URI being the important part here. There is no concept of body data in a GET request.

这篇关于通过HTTP GET发送JSON对象到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆