后台日志
2019-06-13 11:28:28.414 WARN 53716 --- [ XNIO-1 task-15] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public org.springblade.core.tool.api.R org.springblade.admin.controller.TestController.test(org.springblade.admin.controller.TestVO)]
后台controller
@Slf4j @RestController @AllArgsConstructor @RequestMapping(value="/front/test",produces = "application/json;charset=utf-8") @Api(value = "前端接口", tags = "前端接口") public class TestController { @PostMapping("/testPost") @ResponseBody public R test(@RequestBody TestVO test){ return R.data(test); } }
前端ajax调用没问题,Android端 使用httpClient 和OkHttp调用都是返回400 Bad Request
经过一下午的跟踪代码,调试发现
org.springblade.core.tool.support.xss.XssHttpServletRequestWrapper类中的getInputStream()方法
if (!super.getHeader("Content-Type").equalsIgnoreCase("application/json") && !super.getHeader("Content-Type").equalsIgnoreCase("application/json;charset=UTF-8")){
return super.getInputStream();
}
由于 okHttp中默认的Content-Type是"application/json;空格charset=UTF-8"中间有空格 导致走这里的分支 获取不到请求参数报错
扫一扫访问 Blade技术社区 移动端