rest - 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 对象作为响应。
解决方案
推荐阅读
- android - 是否可以在 Jenkins Server 上安装 Android SDK?
- rpa - 是否有一种通用的方法可以强制您的 BOT 闯入 Automation Anywhere?
- database - 隔离级别的更改如何影响 Galera Cluster
- javascript - 如何从mysql连接检查回调函数中获取返回数据?
- typescript - 是否可以创建一个类或接口来继承一个类型的所有属性
- angular - Angular CLI“未知选项:'--sourcemap'”错误
- python - 从另一个模型的方法为模型创造价值
- graph - 如何对个人提供的服务进行数据建模背书,图数据建模
- dart - 如何在颤动中绘制一个扇区?
- c++ - 你如何模拟一个作为被测 gmock 类的一部分的函数?