7
我正在使用apache HttpClient
到后几个文件到服务器。下面的代码:HTTP multipart和chunking可以共存吗?
public static HttpResponse stringResponsePost(String urlString, String content, byte[] image,
HttpContext localContext, HttpClient httpclient) throws Exception {
URL url = new URL(URLDecoder.decode(urlString, "utf-8"));
URI u = url.toURI();
HttpPost post = new HttpPost();
post.setURI(u);
MultipartEntity reqEntity = new MultipartEntity();
StringBody sb = new StringBody(content, HTTP_CONTENT_TYPE_JSON, Charset.forName("UTF-8"));
ByteArrayBody ib = new ByteArrayBody(image, HTTP_CONTENT_TYPE_JPEG, "image");
reqEntity.addPart("interview_data", sb);
reqEntity.addPart("interview_image", ib);
post.setEntity(reqEntity);
HttpResponse response = null;
response = httpclient.execute(post, localContext);
return response;
}
的问题是,MultipartEntity
类仅有isChunked()
方法(它始终返回false),没有“setChunked(布尔)”选项,如果我希望能够为我多实体卡住编码。
我的问题是:
可以根据协议规范HTTP多和分块共存?如果不是,为什么其他实体像
InputStreamEntity
类有setChunked(boolean)
其中MultipartEntity
没有?有没有什么办法可以一次启动多个文件,启用分块功能,更适合使用apache库?