简体   繁体   English

HttpClient 3.x中的InputStreamBody等效项

[英]InputStreamBody equivalent in HttpClient 3.x

In a previous question of mine I got the following answer, which is perfect, but if I want to write my client with HttpClient 3.x, what is the equivalent code? 在我的上一个问题中,我得到了以下答案,这是完美的,但是如果我想用HttpClient 3.x编写客户端,等效代码是什么? Especially "InputStreamBody(new FileInputStream(file)"? 特别是“ InputStreamBody(新的FileInputStream(文件)”)?

Just add different multipart parts with same file content but a different part and filename. 只需添加具有相同文件内容但具有不同部分和文件名的不同多部分。 With InputStreamBody you can specify a different filename for each part. 使用InputStreamBody,可以为每个部分指定不同的文件名。 Eg 例如

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"));
// ...

Thanks 谢谢

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM