androidapachehttpmultipartentity

Is it possible to have a nested MultipartEntities or FormBodyPart in a multipart POST?


I'm trying to make something the following server POST request using MultipartEntity:

parameters: {"parameter1"=>"parameter1", "parameter2"=>{"sub_parameter1"=>"sub_parameter1", "sub_parameter2"=>"sub_parameter2"}}

I am currently using something like:

multipartEntity.addPart("parameter1", new StringBody("parameter1"));

FormBodyPart parameter2 = new FormBodyPart("parameter2", new StringBody("")); // It wouldn't allow a null ContentBody

parameter2.addField("sub_parameter1", "sub_parameter1");
parameter2.addField("sub_parameter2", "sub_parameter2");

However, the sub fields do not carry though. I just get:

parameters: {"parameter1"=>"parameter1", "parameter2"=>""}

How do I create a nested structure in either the MultipartEntity or the FormBodyPart elements it contains?


Solution

  • once you've seen how the form entries are transferred over HTTP connection, you'll understand it's impossible to have anything nested with the multiform request as well as with the url-encoded request.

    things are very simple. multipart form request has the format of:

    --- content-boundary ---
    Content-Disposition: form-data; name="form_data_name"
    
    [content (skipped)]
    --- content-boundary ---
    

    that's it. there's stream of single data form entries in the format: [form entry name] -> [form entry content] that repeats for every entry in the form. it's not recursive, therefore there may not be any nested structures.

    Sources:

    1. 17.13.4 Form content types
    2. RFC 2045 Internet Message Bodies