等效于HttpClient 3.x的InputStreamBody [英] InputStreamBody equivalent in HttpClient 3.x

查看:90
本文介绍了等效于HttpClient 3.x的InputStreamBody的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)"?

只需添加具有相同文件内容但具有不同部分和文件名的不同多部分.使用InputStreamBody,可以为每个部分指定不同的文件名.例如

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

谢谢

推荐答案

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

这篇关于等效于HttpClient 3.x的InputStreamBody的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆