---
title: "The request sent by the client was syntactically incorrect"
author: "ranyut"
date: "2015-11-16T16:27:18Z"
tags: []
categories: ["开源软件"]
slug: "the-request-sent-by-the-client-was-syntactically-incorrect"
draft: false
lastmod: "2015-11-16T16:27:18Z"
id: 2257103
url: "https://just4java.iteye.com/blog/2257103"
---

## 解决 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()只能获取一次的问题](http://ayaoxinchao.iteye.com/blog/2110902)