2012-10-11 60 views
0

我正在構建一個使用MultipartEntity和FormBodyPart創建多部分請求的HTTP客戶端。但是我不清楚如何將XML內容添加到請求主體本身。最後,請求應該如下所示:MultipartEntity和Request Body

--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似乎沒有任何方法添加到主體本身。有什麼建議麼?

回答

0

除非我失去了一些東西應該是很瑣碎

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

的問題是,當我這樣做請求在服務器出現故障。我沒有控制服務器。服務器似乎從當前部分的主體讀取數據,而不是按名稱查找部分。有任何想法嗎? – mithrandir