Skip to content Skip to sidebar Skip to footer

Httpclient Post With Content-disposition

Good evening. Usually I'm working with post request like thatname1=value1&name2=value2 and my code is List nameValuePairs = new ArrayList

Solution 1:

You'll need to utilize HttpClient's HttpMime support. This is not included out of the box with Android so you will have to bundle it with your application.

An example, based on your post could be accomplished as follows:

    MultipartEntity mpe= newMultipartEntity();
    FormBodyPart part1= newFormBodyPart("PERSON*1[F*2][2664]", newStringBody("value1"));
    FormBodyPart part2= newFormBodyPart("PERSON*1[I*3][2776]", newStringBody("value2")); 
    FormBodyPart part3= newFormBodyPart("PERSON*1[O*4][2778]", newStringBody("value3"));
    mpe.addPart(part1);
    mpe.addPart(part2);
    mpe.addPart(part3);

An example of the above output to a stream would be as follows:

--ZV5t1WLAh04TJTqjyBJBSDL3M69xu0A
Content-Disposition: form-data; name="PERSON*1[F*2][2664]"Content-Type: text/plain; charset=US-ASCIIContent-Transfer-Encoding: 8bit

value1
--ZV5t1WLAh04TJTqjyBJBSDL3M69xu0A
Content-Disposition: form-data; name="PERSON*1[I*3][2776]"Content-Type: text/plain; charset=US-ASCIIContent-Transfer-Encoding: 8bit

value2
--ZV5t1WLAh04TJTqjyBJBSDL3M69xu0A
Content-Disposition: form-data; name="PERSON*1[O*4][2778]"Content-Type: text/plain; charset=US-ASCIIContent-Transfer-Encoding: 8bit

value3
--ZV5t1WLAh04TJTqjyBJBSDL3M69xu0A--

I believe the library is more or less stand-alone and can be retrieved from the httpclient website.

Post a Comment for "Httpclient Post With Content-disposition"