I am using Apache HTTPClient 4. I am doing very normal multipart stuff like this:
val entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("filename", new FileBody(new File(fileName), "application/zip").asInstanceOf[ContentBody])
entity.addPart("shared", new StringBody(sharedValue, "text/plain", Charset.forName("UTF-8")));
val post = new HttpPost(uploadUrl);
post.setEntity(entity);
I want to see the contents of the entity (or post, whatever) before I send it. However, that specific method is not implemented:
entity.getContent() // not defined for MultipartEntity
How can I see what I am posting?
Use the
org.apache.http.entity.mime.MultipartEntity
writeTo(java.io.OutputStream) method to write the content to anjava.io.OutputStream
, and then convert that stream to aString
orbyte[]
:Note: this only works for multipart entities both smaller than 2Gb, the maximum size of a byte array in Java, and small enough to be read into memory.
Do you not know the content? Although, you are building the
StringBody
by supplyingsharedValue
. So, how could it be different thansharedValue
.I have printed the Multipart request by following code, You can try like