首页 > 解决方案 > SprintBoot 内容类型为空

问题描述

我有一个实现 PUT 方法的 springboot 应用程序。客户端正在向我的应用程序发送 PUT 请求,但 Header “Content-type” 为空......事实上,客户端没有发送“Content-type”,所以 SpringBoot 实际上拒绝了这个请求,因为它无法处理空内容类型。

13:24:13.658 [http-nio-8080-exec-3] DEBUG vlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Resolving exception from handler [null]: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'null' not supported

有没有一种方法可以让 SpringBoot 接受 null Content-type 并使其假定一些默认的 content-type 值?

控制器看起来像:

@RequestMapping(value="/xxxx", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.TEXT_PLAIN_VALUE)
@ApiResponses(value = {@ApiResponse(code=200, message="OK", response=yyyyyyyy.class)})
public ResponseEntity<?> xxxxxx(@RequestBody String s)

所以这个想法是使用一个计划文本并产生一个 json 对象作为响应。

标签: restspring-bootcontent-type

解决方案


推荐阅读