21

I am trying to carry JSON data in an HTTP GET request message, but my Spring MVC server can't seem to retrieve the JSON data from the GET request body.

Mario Cervera
  • 641
  • 1
  • 8
  • 19
Hongbo Tian
  • 223
  • 1
  • 2
  • 5

1 Answers1

27

HTTP's GET method does not include a request body as part of the spec. Spring MVC respects the HTTP specs. Specifically, servers are allowed to discard the body. The request URI should contain everything needed to formulate the response.

If you need a request body, change the request type to POST, which does include the request body.

Leland Barton
  • 2,884
  • 17
  • 17
  • 6
    Which spec? Based on the link (https://stackoverflow.com/questions/978061/http-get-with-request-body#comment68112820_983458) "HTTP/1.1 spec" is now obsolete. – skryvets Jun 11 '19 at 16:22
  • 3
    Exactly. The HTTP specs nowadays says nothing of the sort (other than the GET request body semantics are independent of the GET request processing semantics.) – luis.espinal Oct 10 '19 at 14:39
  • 1
    POST method is not just for changes like add / delete etc.. ? – Adir D Oct 18 '20 at 13:40
  • Indeed as you have pointed out Spring must be discarding the body for GET call. I just want to further discuss -- The problem with using POST, just for the sake of including a requestbody is that - we are sort of changing the meaning of the call. As in, All is want to do is "get" a resource and i want to specify additional criteria in request body. When I use a post call, it appears as though I want to save something, but I am actually not saving anything. That is why I feel that RequestBody should be supported for GET calls. Please correct me if I am missing anything here. Thanks. – Ashish Mishra Apr 30 '21 at 14:24