Spring @RequestBody 是否支持 GET 方法? [英] Does Spring @RequestBody support the GET method?

查看:65
本文介绍了Spring @RequestBody 是否支持 GET 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 HTTP GET 请求消息中携带 JSON 数据,但我的 Spring MVC 服务器似乎无法从 GET 请求正文中检索 JSON 数据.

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.

推荐答案

HTTP 的 GET 方法不包括请求正文作为规范的一部分.Spring MVC 尊重 HTTP 规范.具体来说,允许服务器丢弃正文.请求 URI 应包含制定响应所需的所有内容.

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.

如果您需要请求正文,请将请求类型更改为 POST,其中包含请求正文.

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

这篇关于Spring @RequestBody 是否支持 GET 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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