0

Let's say I have:

MultipartEntity reqEntity = new MultipartEntity();          
try {
    StringBody title = new StringBody("title");
    StringBody des = new StringBody("description");
    StringBody msg = new StringBody("message");

    reqEntity.addPart("title", title);
    reqEntity.addPart("des", des);
    reqEntity.addPart("msg", msg);
} catch (UnsupportedEncodingException e) {}

then i do a POST request with the above reqEntity. before moving forward to execute this request, is there a way to get the key-value pairs from reqEntity? I want to store the info in disk in case the request fail.

I don't remember where I found from stackoverflow, but this seems to be helpful

ByteArrayOutputStream bytes = new ByteArrayOutputStream();
reqEntity.writeTo(bytes);
String content = bytes.toString();

print out the content gives me key and value, but also a lot of junk that not easily to be converted to key-value pairs. here's an example

--YnPsBODbYoAYBjIzGhYWzvn-pbuSdN9ptrzHc
Content-Disposition: form-data; name="des"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit

description

Thanks for the help!

user1865027
  • 2,915
  • 4
  • 26
  • 56
  • It that what you want to do http://stackoverflow.com/questions/8120220/how-to-use-parameters-with-httppost ? – atok Dec 10 '14 at 22:16
  • no, i know how to do a POST request, but i'm curious about how to get the parts that added through `reqEntity.addPart` – user1865027 Dec 10 '14 at 22:19

0 Answers0