Java Apache set additional parameters in "Content-Disposition:"

30 views Asked by At

I am using java Apache 5.3.1, I am trying to send a multipart with XML, and need the following "Content-Disposition:" set -

Content-Disposition: form-data; name="xml"; filename="test.xml"

If I use this I get most if it -

MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.addPart("xml", new StringBody(xml, ContentType.APPLICATION_XML));

but that only produces

Content-Disposition: form-data; name="xml"

How do I get it to add the 'filename="test.xml"' part? Thanks

1

There are 1 answers

0
Jeremy On

You have to use builder.addBinaryBody and it will add the filename.

builder.addBinaryBody(
  "xml",
  xml.getBytes(),
  ContentType.APPLICATION_XML,"test.xlm");