Spring Boot RestController-PostMapping-将请求主体作为InputStream

阿提拉:

在Spring Boot RestController中使用PostMapping时,是否有一种简单的方法可以将POST HTTP请求的主体作为InputStream处理?

接受来自Multipart HTTP POST请求的文件上传作为MultipartFile实例非常简单,但是我希望能够简单地将二进制内容发布到HTTP端点并将其作为InputStream处理。

Spring Boot有可能吗?

例如,使用以下邮递员POST:

在此处输入图片说明

马蒂亚斯(Matthias):

我知道两种可能的方法

以HttpEntity

@PostMapping
public ResponseEntity<String> post(HttpEntity<byte[]> requestEntity) {
    return ResponseEntity.ok(new String(requestEntity.getBody()));
}

接受整个请求

@PostMapping
public ResponseEntity<String> post(HttpServletRequest request) {
    request.getInputStream();
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring Boot RestController:拦截传入的请求

Spring Boot PostMapping 总是收到空值

Spring Boot @PostMapping 有没有办法检测传入请求正文中的空字段?

没有.csrf()。disable()的Spring Boot RestController DELETE请求失败

自动配置RestController Spring Boot

Spring Boot @RestController 和 @Controller

将JSON数组发布到Spring Boot RestController

Spring Boot PostMapping 反序列化長數組

Spring Boot RestController不返回JSON数据

RestController的设计难题-Spring Boot REST API

RestController 返回 404 (Spring Boot 2.3.7)

在Spring Boot中拦截对RestController的调用

Spring Boot RestController,在错误状态响应主体上,错误消息为空

Spring Boot Restcontroller作为单元测试中的内部类(webmvctest)

Spring Boot @RestController 无法自动将响应转换为 JSON

Spring Security 中的 PostMapping

API不会使用@PostMapping接收信息,但是使用@RequestMapping是。Spring Boot,Kotlin,REST API

Spring Boot,Maven,在派生项目中禁用特定的RestController

RestController在oauth2 Spring Boot中不起作用

可以使用属性启用/禁用Spring Boot @RestController吗?

Spring Boot-RestController反序列化YAML上传?

为什么RestController在Spring Boot中不起作用?

Spring-Boot Maven,缺少依赖项@RestController

如何使用Spring Boot @RestController流式处理分块的响应

Spring Boot @restcontroller到@controller具有分页

Spring Boot RestController不适用于lombok

Spring boot 中的 RestController-404 错误而不是 JSON 对象

使用方面时未调用 Spring Boot RestController 的构造函数

从Spring Boot RestController使用多个服务时获取ClassCastException