HttpClient 3.x 中的 InputStreamBody 等效项

发布于 2024-09-27 04:21:55 字数 573 浏览 3 评论 0原文

在我之前的一个问题中,我得到了以下答案,这是完美的, 但如果我想用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

殤城〤 2024-10-04 04:21:55

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

The equivalent class is org.apache.commons.httpclient.methods.InputStreamRequestEntity

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文