The request sent by the client was syntactically incorrect.
2016-09-20 16:51
555 查看
客户端使用httpclient上传文件到服务端由spring mvc接收
本来用addBinaryBody传入File参数是正常运作的
然后为了实现进度条跟踪而改为传入InputStream参数就报错了
错误:
由于使用了Commons.io的CountingInputStream,还一度认为是inputstream不兼容的问题
后来甚至尝试直接覆写InputStreamBody的write方法来手动跟踪进度,结果还是同样的错误,
在阅读源码的时候才注意到
而原来传入File的方法,则根据文件获取了名字
改为使用public MultipartEntityBuilder addBinaryBody(
final String name, final InputStream stream, final ContentType contentType,
final String filename)
方法手动添加filename
加上名字之后果然就没有报错了,顺利上传并跟踪更新了进度条。
本来用addBinaryBody传入File参数是正常运作的
然后为了实现进度条跟踪而改为传入InputStream参数就报错了
错误:
Required request part '' is not present
The request sent by the client was syntactically incorrect.
由于使用了Commons.io的CountingInputStream,还一度认为是inputstream不兼容的问题后来甚至尝试直接覆写InputStreamBody的write方法来手动跟踪进度,结果还是同样的错误,
在阅读源码的时候才注意到
public MultipartEntityBuilder addBinaryBody(final String name, final InputStream stream) { return addBinaryBody(name, stream, ContentType.DEFAULT_BINARY, null); }最后那个参数直接传入了空
而原来传入File的方法,则根据文件获取了名字
public MultipartEntityBuilder addBinaryBody( final String name, final File file) { return addBinaryBody(name, file, ContentType.DEFAULT_BINARY, file != null ? file.getName() : null); }
改为使用public MultipartEntityBuilder addBinaryBody(
final String name, final InputStream stream, final ContentType contentType,
final String filename)
方法手动添加filename
加上名字之后果然就没有报错了,顺利上传并跟踪更新了进度条。
相关文章推荐
- spring MVC 错误The request sent by the client was syntactically incorrect ()的解决
- The request sent by the client was syntactically incorrect.
- HTTP Status 400 - description:The request sent by the client was syntactically incorrect.
- spring mvc 数据绑定问题 提交表单提示HTTP status 400, The request sent by the client was syntactically incorrect
- spring mvc 数据绑定问题 提交表单提示HTTP status 400, The request sent by the client was syntactically incorrect
- The request sent by the client was syntactically incorrect ().问题排查
- springmvc提交表单,格式问题:The request sent by the client was syntactically incorrect.
- The request sent by the client was syntactically incorrect
- Springmvc注解开发:日期类型参数封装报错:The request sent by the client was syntactically incorrect.
- Spring MVC "The request sent by the client was syntactically incorrect ()"解决办法
- 错误:The request sent by the client was syntactically incorrect的解决
- The request sent by the client was syntactically incorrect.
- Http 400 --- The request sent by the client was syntactically incorrect
- Spring MVC "The request sent by the client was syntactically incorrect ()"解决办法
- The request sent by the client was syntactically incorrect
- spring mvc 400,The request sent by the client was syntactically incorrect的问题
- javaweb项目错误400-The request sent by the client was syntactically incorrect.
- spring mvc错误:The request sent by the client was syntactically incorrect的解决
- The request sent by the client was syntactically incorrect. 错误以及spring事物
- The request sent by the client was syntactically incorrect - Spring mvc