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!