The request sent by the client was syntactically incorrect

解决 spring mvc 下post json出现HTTP Status 400 The request sent by the client was syntactically incorrect

 

当你觉得你的配置一切正常,并且无数次检查了请求json参数与javabean都是一致的,但就是报上面的错的时候,那你可能遇到跟我一样的问题。

 

跟踪Spring执行@RequestBody的过程发现底层的真实错误是:

 

org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: No content to map due to end-of-input
 at [Source: org.apache.catalina.connector.CoyoteInputStream@7abd6f93; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
 at [Source: org.apache.catalina.connector.CoyoteInputStream@7abd6f93; line: 1, column: 1]

 也就是没有内容,说明参数没有传进来。

 

 

实事上参数是有的,只不过参数是通过InputStream写入的,而在过滤器或执行@RequestBody之前的任何地方你可能从流中读出了json参数,而ServletStream是不可重复读的,所以当@RequestBody再从InputStream中读参数时就为空了。

 

知道原因了就好解决,inputStream不能重复读,但你又必须读多次怎么办?

解决办法:

request.getInputStream()只能获取一次的问题

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值