Sending JSON object to the server via http GET

前端 未结 3 705
悲哀的现实
悲哀的现实 2020-12-19 20:18

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.

相关标签:
3条回答
  • 2020-12-19 20:58

    No :-) Thats not how get works.

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

    (see 9.3 GET)

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

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

    0 讨论(0)
  • 2020-12-19 21:05

    Try changing method to public ActionResult Screenreport(HttpRequestMessage request)

    Then use below code to get JSON object.

    data = request.RequestUri.Query;
    data = HttpUtility.ParseQueryString(data).Get("request");

    0 讨论(0)
  • 2020-12-19 21:12

    Try this example in Javascript:

    var someObject = {
       id:123456,
       message:"my message",
    }
    
    var objStr = JSON.stringify(someObject);
    
    var escapedObjStr = encodeURIComponent(objStr);
    
    var getUrlStr = "http://myserver:port?json="+escapedObjStr
    

    and now you can forward this URL to your server. I know this is not in any .NET language but you can definitely find the equivalent methods used, or just use the JS right away.

    0 讨论(0)
提交回复
热议问题