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.
Asked
Active
Viewed 2.3k times
21
-
you'll have to use the query string, or POST/PATCH/PUT/DELETE – Neil McGuigan Jan 23 '16 at 00:21
1 Answers
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
-
6Which 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
-
3Exactly. 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
-
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