简体   繁体   English

我可以在 Spring Boot 中使用请求正文执行 GET 吗?

[英]Can I do a GET with request body in Spring Boot?

I'm using Spring Boot and Spring MVC and I need to make a GET with a request body.我正在使用 Spring Boot 和 Spring MVC,我需要使用请求正文进行 GET。 Is this possible?这可能吗?

I tried this but it's not working.我试过了,但没有用。 I get 404.我得到 404。

@RestController
@RequestMapping("/api")
public class HomeController {

    @GetMapping("/v1/foo")
    public ApiRes postBody(@RequestBody ApiReq apiReq) {
        ...
    }
}

Technically it is possible but it is against the HTTP API Design Guidelines.从技术上讲这是可能的,但它违反了 HTTP API 设计指南。 Request-Bodys should only be used for POST or PUT. Request-Body 应该只用于 POST 或 PUT。

For further information: https://swagger.io/resources/articles/best-practices-in-api-design/更多信息: https://swagger.io/resources/articles/best-practices-in-api-design/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Spring Boot 的 ExceptionHandler 中的请求中获取正文数据? - How can I get a body data from the request in an ExceptionHandler in Spring Boot? 如果http请求的内容类型为urlencoded,如何让我的spring启动控制器读取我对某个对象的http请求的主体? - How can I get my spring boot controller to read the body of my http request to an object if the http request has content type urlencoded? 使用spring数据jpa的spring boot。 如何从请求主体执行实体的部分更新? - Spring boot with spring data jpa. How can i perform partial update of entity from request body? Spring Boot - 如何获取请求的基本URL - Spring Boot - how do I get the base url of a request 如何在 Spring Boot 中使用 @NotEmpty 约束来验证 HTTP 请求主体? - How do I use @NotEmpty constraint to validate an HTTP request body in Spring Boot? 如何检测 Spring Boot 中请求正文中的 JSON 对象是否为空? - How can I detect if the JSON object within Request body is empty in Spring Boot? Spring 使用@RequestBody 时启动获取请求正文 - Spring Boot get the request body while using @RequestBody 在 java/spring boot 中的 HTTP GET 请求中发送 JSON 正文 - Send JSON body in HTTP GET request in java/spring boot 缺少请求正文的 Spring Boot POST 请求? - Spring Boot POST request with missing request body? Spring boot 的 Postman Post 请求保存了整个 JSON 正文,而不仅仅是字段值。 我该如何解决? - Postman Post request for Spring boot saves the entire JSON body instead of just the field value. How do I fix this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM