InputStreamBody相当于HttpClient 3.x

问题描述:

在我以前的问题中,我得到了以下答案,这是完美的, 但如果我想用HttpClient 3.x编写我的客户端,那么等效代码是什么? 尤其是“InputStreamBody(新的FileInputStream(文件)”?InputStreamBody相当于HttpClient 3.x

只是同一个文件中的内容,但不同的部分和文件名添加不同的多部分。随着InputStreamBody您可以指定每个部分不同的文件名。例如

MultipartEntity entity = new MultipartEntity(); 
entity.addPart("file1", new InputStreamBody(new FileInputStream(file), "name1.ext")); 
entity.addPart("file2", new InputStreamBody(new FileInputStream(file), "name2.ext")); 
entity.addPart("file3", new InputStreamBody(new FileInputStream(file), "name3.ext")); 
// ... 

由于

等效类是org.apache.commons.httpclient.methods.InputStreamRequestEntity

+0

由于我将吨呃 – Antonis 2010-10-13 20:07:27