HttpClient 3.x 中的 InputStreamBody 等效项
在我之前的一个问题中,我得到了以下答案,这是完美的, 但如果我想用 HttpClient 3.x 编写客户端,等效代码是什么? 特别是“InputStreamBody(new FileInputStream(file)”?
只需添加具有相同文件内容但不同部分和文件名的不同多部分部分。使用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"));
// ...
谢谢
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?
Especially "InputStreamBody(new FileInputStream(file)"?
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. E.g.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
等效的类是 org.apache.commons.httpclient.methods.InputStreamRequestEntity
The equivalent class is
org.apache.commons.httpclient.methods.InputStreamRequestEntity