MultipartEntity和Request Body

时间:2012-10-11 14:34:45

标签: multipartform-data apache-httpclient-4.x

我正在构建一个使用MultipartEntity和FormBodyPart创建多部分请求的HTTP客户端。但是我不清楚如何将一些XML内容添加到请求主体本身。最后,请求应如下所示:

--ejjeeffe0
request-id: 99f9a899-5e25-45fb-9faa-d92320f60f7e
content-length: 1915
Function: CORE
content-type: text/xml
request-type: data
some-other header attributes: values

<?xml version="1.0" encoding="utf-8"?>
<xml payload here>

--ejjeeffe0
request-id: b7612e0a-b117-4ad7-a11f-2ea5a7e5fdc1
request-type: statistical_record
content-type: text/plain
content-length: 0
some-other attributes: values

--ejjeeffe0--

FormBodyPart似乎没有任何方法可以添加到正文本身。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

除非我遗漏了某些东西,否则它应该是非常简单的

entity.addPart(new FormBodyPart("my-text", new StringBody(somestring)));
entity.addPart(new FormBodyPart("my-data", new FileBody(somefile)));