【发布时间】:2012-01-28 13:46:50
【问题描述】:
我正在尝试使用 apache http 客户端 v4.x。
对于特定情况,我必须提出多部分表单请求...
使用以下代码在 java 中发出多部分表单请求--
HttpPost httppost = new HttpPost("http://localhost:8080" + "/servlets-examples/servlet/RequestInfoExample");
FileBody bin = new FileBody(new File(args[0]));
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("bin", bin);
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
在我的例子中,我有一个文件体的字节流,
byte[] bytes = value.toBinary(charset);
现在我想将此文件(字节流)添加到多部分实体中,以便我可以发出多部分发布请求...我该怎么做?
【问题讨论】:
标签: java httpclient multipartform-data apache-httpcomponents