出现:Corrupt form data: premature ending错误。
客户端是别人写的,动不了代码,如下:
//设置连接时间
RequestConfig reqconfig = RequestConfig.custom()
.setConnectTimeout(30000).setConnectionRequestTimeout(15000)
.setSocketTimeout(30000).build();
// 文件参数设置
HttpPost httppost = new HttpPost(server_url);
MultipartEntity mpEntity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName(HTTP.UTF_8)); // 如果Charset.forName(HTTP.UTF_8)写为null就没错了。
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("file", cbFile);
httppost.setEntity(mpEntity);
HttpResponse response = httpclient.execute(httppost);服务端接收代码:
List<UploadFile> uploadFiles = this.getFiles();
异常的位置在cos-2019.8.jar的MultipartParser.java, 207 line:
String line = readLine();
if (line == null) {
throw new IOException("Corrupt form data: premature ending");
}
// See if this line is the boundary, and if so break
if (line.startsWith(boundary)) {
break; // success
}
} while (true);附件都换了几个,大小100K
请求帮助。
P.S: 用commons-upload.jar (纯手工接收file),或者不用jfinal,改为springmvc都可以接收附件。
HttpServletRequest request = getRequest();
然后将 request 这个对象传递给 commons-upload.jar 中的相关类进行解析,commons-upload.jar 中提供了对于 HttpServletRequest 类型对象的解析类
此外,建议先检查一下是不是 getFile() 使用的时机不对,如果有拦截器的话,也要在拦截器中首先调用
getFile()
否则无法正常工作,这个在文档中有过说明:
https://www.jfinal.com/doc/3-11